Page 1 of 1

[ZScript] Universal mirrored deaths

PostPosted: Mon Oct 14, 2019 10:38 am
by m8f


Download
Source code

Features

- 50% chance of death animation being mirrored horizontally.
- raising animations are flipped too.
- works with any game and mod (hopefully).
- blacklist to exclude specific monsters from mirroring.
- bonus feature: alternating mirroring (controlled by df_alternate CVar).

Can be included in mods, or used as an addon by itself.

This mod is a part of m8f's toolbox.

Re: [ZScript] Universal mirrored deaths

PostPosted: Thu Dec 26, 2019 1:15 am
by bLUEbYTE
I love non-intrusive mini mods like this that add variety.

Re: [ZScript] Universal mirrored deaths

PostPosted: Sat Dec 28, 2019 10:53 pm
by bLUEbYTE
Hi m8f,
I added this into my Universal Entropy mod. Two questions;

Why did you need to blacklist chaingunguy and cyberdemon from being flipped? In my testing flipped bodies for these look just fine.

Why not go further and flip the sprites on Spawn, to create left/right handed variants? As far as I can tell, the projectiles do not originate from the arms anyway. For example, Cyberdemon's rockets seem to fly off his belly.

Re: [ZScript] Universal mirrored deaths

PostPosted: Sat Dec 28, 2019 11:36 pm
by m8f
Because these monsters are asymmetric, and it will look wrong if the monster weapon flips to the other hand on death animation.

About flipping monsters from the start - I simply didn't think about that.

Re: [ZScript] Universal mirrored deaths

PostPosted: Sun Dec 29, 2019 12:10 am
by bLUEbYTE
m8f wrote:Because these monsters are asymmetric, and it will look wrong if the monster weapon flips to the other hand on death animation.

About flipping monsters from the start - I simply didn't think about that.


I replaced all the code in death-flip with this:
Code: Select allExpand view
         // Flip
         let flip = random(0, 1);
         if (flip == 1)
         {
            a.A_SetScale(-a.Scale.X, a.Scale.Y);
         }


All looking good to me, including chaingunner death animations, and they do come back with the correct orientation if revived. I guess the engine doesn't clear the actor's sprite scaling values when it becomes a corpse, rendering all the Inventory stuff unnecessary. But if I'm missing something here, let me know.

Re: [ZScript] Universal mirrored deaths

PostPosted: Sun Dec 29, 2019 1:10 am
by 3saster
bLUEbYTE wrote:All looking good to me, including chaingunner death animations, and they do come back with the correct orientation if revived. I guess the engine doesn't clear the actor's sprite scaling values when it becomes a corpse, rendering all the Inventory stuff unnecessary. But if I'm missing something here, let me know.


The issue would be if the monster's behaviour is related to its sprite. Consider a Cyberdemon that has been modified to shoot a rocket from its arm instead of its chest. If you mirror it on spawn, then when it fires, its animation will not match its behaviour anymore. If you could mirror EVERYTHING about the actor, including the behaviours, then this would be good, but I'm not sure that's actually possible in a generic way.

Re: [ZScript] Universal mirrored deaths

PostPosted: Sun Dec 29, 2019 6:31 am
by bLUEbYTE
Well, forget what I said above regarding my super simple 3-line flip code working fine... It doesn't. Although admittedly it looks pretty funny, it causes the monsters to moonwalk :lol: .

So I'm back to using m8f's full code in my mod. Lesson learned.

Re: [ZScript] Universal mirrored deaths

PostPosted: Fri Oct 09, 2020 12:22 pm
by eviltechno
Any reason why it doesn't run well with the zombiemans in Brutal Doom? The deathpic is always default. I think its the same with the pinkies. Any way to fix it?

Re: [ZScript] Universal mirrored deaths

PostPosted: Fri Oct 09, 2020 11:58 pm
by m8f
I noticed that the death animation starts mirrored, and then flips back to default when a zombieman falls on the ground. It's because in Brutal Doom, at this moment dead bodies become invisible and spawn a new actor, for example
Code: Select allExpand view
TNT1 A 0 A_SpawnItem("DeadZombieman1")
Probably this is to make dead bodies shootable. It's a code design choice of Brutal Doom, I cannot fix it in my mod.

If you want Brutal Doom with mirrored shootable corpses, I can recommend BDLite with Universal Gibs.

Re: [ZScript] Universal mirrored deaths

PostPosted: Sat Oct 31, 2020 3:32 am
by MObreck
Out of curiosity was there a reason you chose to use scale.x over the XFLIP flag?

By using the flag method I was able to get the same result while completely eliminating the need for the inventory hack items. I used this script for df_EventHandler and was able to delete df_Unflipper and df_MirroredFlag by doing so:

Code: Select allExpand view
class df_EventHandler : EventHandler
{

// public: // EventHandler /////////////////////////////////////////////////////

  override
  void OnRegister()
  {
    blacklist = new("df_StringSet").init();
  }

  override
  void WorldThingDied(WorldEvent event)
  {
    let thing = event.thing;
    if (thing == NULL) { return; }

    if (blacklist.contains(thing.GetClassName())) { return; }

    bool flipped = df_alternate
                 ? (isPrevFlipped = !isPrevFlipped)
                 : random(0, 1);

    if (flipped)
    {
      flip(thing);
    }
  }

  override
  void WorldThingRevived(WorldEvent event)
  {
    let thing = event.thing;
    if (thing == NULL) { return; }

    if (blacklist.contains(thing.GetClassName())) { return; }

   thing.bXFLIP = false; //Might as well always clear the flag.
  }

// public: /////////////////////////////////////////////////////////////////////

  static
  void flip(Actor thing)
  {
   thing.bXFLIP = true;
  }

// private: /////////////////////////////////////////////////////////////////////

  private df_StringSet blacklist;
  private bool isPrevFlipped;

}

Re: [ZScript] Universal mirrored deaths

PostPosted: Sat Oct 31, 2020 4:09 am
by m8f
There is no much difference between using of scale.x and XFLIP flag. With XFLIP, I'd had to use df_MirroredFlag and df_Unflipper too. The point is, with df_MirroredFlag and df_Unflipper I can save my own mirrored state for the actor. If some mod utilizes scale.x (or XFLIP) and I unconditionally override it, it may result in visual inconsistencies.