Custom Player Class and Translucency

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
SPZ1
Posts: 244
Joined: Wed Aug 02, 2017 3:01 pm
Location: Illinois
Contact:

Custom Player Class and Translucency

Post by SPZ1 »

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 all

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 all

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
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: Custom Player Class and Translucency

Post by Arctangent »

[wiki]A_FadeOut[/wiki] and [wiki]A_FadeIn[/wiki] 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 [wiki]A_FadeTo[/wiki] instead, since it will prevent the alpha from going over or under a cap you manually set. You could also use [wiki]A_SetTranslucent[/wiki], 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.
Locked

Return to “Editing (Archive)”