Can falling damage scale with jump height?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

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.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
Heisanevilgenius
Posts: 95
Joined: Wed Dec 15, 2021 8:38 pm
Graphics Processor: nVidia (Modern GZDoom)

Can falling damage scale with jump height?

Post by Heisanevilgenius »

I'm working on a wad with falling damage and special RPG-like abilities and items that change jump height. Problem is that once your jump stat reaches a certain level, your character takes damage every time they land. Is there a way to alter fall damage on a per player basis so that it scales with their jump height?
User avatar
Hellser
Global Moderator
Posts: 2782
Joined: Sun Jun 25, 2006 4:43 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: Citadel Station

Re: Can falling damage scale with jump height?

Post by Hellser »

Cleaned up thread, all users may now resume scripting!
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Can falling damage scale with jump height?

Post by Jarewill »

Thanks Hellser, let me just repost what I posted prior.

While I don't know how to override default fall damage behavior, I still couldn't find it in the ZScript files, you can write your own fall damage logic in ZScript.
An example taken from Lost Frontier:

Code: Select all

	double pvel; //Save the previous Z velocity to this variable
	Override void Tick()
	{
		pvel=vel.z; //Refer to above
		Super.Tick(); //Let the logic run for a tick for velocity to update
		FallDamage(); //Call the fall damage function
	}
	void FallDamage()
	{
		double cvel = vel.z; //Get current Z velocity, not needed but I did it for readability
		int damage;
		If(pvel<cvel) //If current velocity is bigger than previous velocity (player hit ground)
		{
			If(pvel<=-23&&player&&!(player.cheats&(CF_GODMODE|CF_GODMODE2))){Die(null,null,0,"Falling");} //If the velocity excels -23, kill the player
			Else
			{
				If(pvel<=-16){damage=(int)(pvel);} //Otherwise calculate damage based on velocity
				Else If(pvel<=-11){damage=(int)(pvel)/4;}
				DamageMobj(null,null,-damage,"Falling"); //And damage the player
			}
		}
	}
You will have to alter the math to include the player's jump height (jumpz variable) into account and change how much damage is dealt.
For more context regarding fall speeds, refer to this wiki page.
Heisanevilgenius
Posts: 95
Joined: Wed Dec 15, 2021 8:38 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Can falling damage scale with jump height?

Post by Heisanevilgenius »

Thank you, that's really helpful! It's going to take me a while to figure all this out but I feel more confident I can do it now. :)

I guess I'm going to have to disable the falling damage in MAPINFO since this new special falling damage in Zscript will operate automatically, by the looks of it?
Heisanevilgenius
Posts: 95
Joined: Wed Dec 15, 2021 8:38 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Can falling damage scale with jump height?

Post by Heisanevilgenius »

Woo! I got it to work!

Code: Select all

	Override void Tick()
	{
		pvel=vel.z;
		Super.Tick();
		FallDamage();	
	}
	void FallDamage()
	{
		double cvel = vel.z;
		double jumpvel = pvel+JumpZ;
		int damage;
		If(pvel<cvel)
		{
			If(jumpvel<=-11){damage=(int)((0-jumpvel)*2);}
			If (damage>0) {
				DamageMobj(null,null,damage,"Falling");
			}
		}
	}
I'll probably have to tweak the falling damage formula to get it to a good balance, but I did away with the instakill. You can still die from falling too much but if you get your jump stat really high (and I mean ridiculously high) you can fall almost any height without taking damage.
Post Reply

Return to “Scripting”