Custom Player Class and Translucency

Discuss all aspects of editing for ZDoom.
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Custom Player Class and Translucency

Postby SPZ1 » Sat Sep 23, 2017 5:50 pm

It is as the topic , I cannot seem to make this work! Basically, I want the player sprite to temporarily go translucent while in the Pain state. It works fine for a enemy but not a Player. I've tried to use A_FadeIn(0.333) and A_FadeIn(1.0) in the Spawn, See, Pain, Melee, and Missile frames and the result is the same: The actor will not go translucent while this command is present. Without A_FadeIn() function, the player goes completely transparent after a couple hits and stays there!! Anyway, here is my DECORATE player:

Code: Select allExpand view
ACTOR Earth_Mage : DoomPlayer replaces DoomPlayer {
      Health 100
      Scale 0.125
      Radius 16
      Height 83
      Mass 125
      Speed 1
      PainChance 192
      Player.DamageScreenColor "Magenta", 0.4
      Player.DisplayName "Earth Mage"
      Player.MaxHealth 125
      States {
         Spawn:
            MAIN A 1
         //   MAIN A 0 A_FadeIn(1.0)
            Loop
         See:
            MAIN A 1
            MAIN ABCDEFGH 3
         //   MAIN A 0 A_FadeIn(1.0)
            Loop
         Missile:
         Melee:
            MAIN AIJIA 8
         //   MAIN A 0 A_FadeIn(1.0)
            GoTo See
         Pain:
            MAIN AA 4 A_FadeOut(0.333)
            MAIN AA 6 A_FadeIn(0.333)
            GoTo See
         Death:
         xDeath:
            MAIN A 8 A_FadeOut(0.1)
            Loop
               
      }
}



It works on an enemy character without a problem though:

Code: Select allExpand view
ACTOR Test1 {
      Health 100
      Scale 0.125
      Radius 16
      Height 83
      Mass 125
      Speed 8
      PainChance 192
      MONSTER
      States {
         Spawn:
            MAIN A 1
            MAIN A 1 A_Look
            Loop
         See:
            MAIN A 3
            MAIN BCDEFGH 3 A_Chase("Melee", "Missile")
            Loop
         Missile:
            MAIN A 6
            MAIN I 7 BRIGHT A_FaceTarget
            MAIN J 7 BRIGHT A_SpawnProjectile("IceyStaff_Projectile")
            MAIN I 7 BRIGHT
            MAIN A 6
            GoTo See
         Melee:
            MAIN A 6
            MAIN I 7 BRIGHT A_FaceTarget
            MAIN J 7 BRIGHT A_CustomMeleeAttack(random(3,5)*5)
            MAIN I 7 BRIGHT
            MAIN A 6
            GoTo See
         Pain:
            MAIN AA 5 A_FadeOut(0.333)
            MAIN AA 5 A_FadeIn(0.333)
            GoTo See
         Death:
            MAIN A 5 A_FadeOut(0.1)
            Loop
      }
}


User avatar
SPZ1
 
Joined: 02 Aug 2017
Location: Illinois

Re: Custom Player Class and Translucency

Postby Arctangent » Sat Sep 23, 2017 11:06 pm

A_FadeOut and A_FadeIn by default remove and add from an actor's alpha without limit. Which means they can make it drop below 0 and above 1.0, at which point you'd need to increase them above 0 / reduce them below 1.0 to see any effect.

Which means you're seeing the consequences of the following:

  • Looping the Spawn states and See states will result in the player's alpha increasing by 1.0, at an extreme rate in the case of the Spawn states, while A_FadeIn isn't commented out. This results in the player's alpha shooting up to 36.0 in a second of standing still.
  • The Pain state has a chance to be entered and its function executed during each separate damage instance. So, say, if your player is hit by a SSG or a functionally identical equivalent, it has a 75% chance of reducing its alpha by 0.333. Then it has another 75% chance of reducing it by 0.333. Then another. Then another. Then another. Then another until it's had 20 chances to do this, as the SSG launches 20 hitscans which all count as separate damage instances. This means that a full-power SSG blast will, by average, reduce your player's alpha by 4.995, likely resulting in an alpha of about -2.995 to -0.995 if its alpha hasn't been shot up ridiculously by standing still. Combine that with the fact that only the last instance will raise this by 0.333 ( since the other A_FadeIn is canceled out by the second A_FadeOut ) and it's not hard to see why the player would remain invisible for a while if they didn't stand still and let the extreme rate of alpha increase go into effect, especifcally if they get constantly bombarded by damage instances that don't allow the A_FadeIns following the Pain state to apply.

So, yeah. Not really surprising that it ends of being all wonky.

Your best bet is to use A_FadeTo instead, since it will prevent the alpha from going over or under a cap you manually set. You could also use A_SetTranslucent, since you're not exactly utilizing the dynamic transluency adjustment the Fade functions provide. Finally, you can use A_FadeIn and A_FadeOut's FTF_CLAMP flag to prevent them from setting the alpha below 0 and above 1.0, which will also disable one of the main reasons why I would never recommend using the Fade functions on a player: the fact that they will remove an actor at or below 0 alpha after altering its alpha, which may have been special cased to not apply to player actors but either way removing a player actor while a player is current controlling it is a Bad Thing.

That will cause ZDoom to crash. Because it's that Bad.
User avatar
Arctangent
squawky
 
Joined: 06 Nov 2014
Discord: SquawkyAtan#2371


Return to Editing (Archive)

Who is online

Users browsing this forum: Yandex [Bot] and 4 guests