Need help finding velocity needed to reach certain heights

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!)
User avatar
Dark-Assassin
Posts: 742
Joined: Thu Mar 19, 2009 3:40 am
Location: South Australia

Need help finding velocity needed to reach certain heights

Post by Dark-Assassin »

I'm trying to write a jump pad that will boost a player to a specific height using arguments or just use the sector's height if none are set.
However I have no idea how to find out how to determine the needed vertical velocity to reach those heights from the floor. It also needs to take account of variable gravity values too, not just Doom's 800.
I have everything but that formula. Results must be in fixed point too as it is done with ACS to keep compatibility with Zandronum.

If anyone could help me with this, it would be really appreciated.
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: Need help finding velocity needed to reach certain heigh

Post by Gutawer »

The basic formula for this is the formula v^2 = u^2 + 2as, where v is the final velocity (we're looking at the top of a jump arc here, which is always when the velocity is 0, as the body is turning from going up to going down), u is the initial velocity, i.e. what you want, a is the acceleration (this is the actor's gravity as a negative value, i.e. -1 normally, but this can be gotten with ACS via APROP_Gravity, although this doesn't include sector/map gravity - I'm not sure how you'd get that in ACS), and s is the displacement, in this case this is height. So you have 0 = u^2 + 2as, which can be rearranged to make u = sqrt(-2as), which is the velocity you're looking for. Just as a general thing, I would also stick something like 64 units onto the height to add some lenience for things like numerical errors and the player needing to actually land on a ledge after reaching their top height, which will inevitably involve falling onto the ground.
User avatar
Dark-Assassin
Posts: 742
Joined: Thu Mar 19, 2009 3:40 am
Location: South Australia

Re: Need help finding velocity needed to reach certain heigh

Post by Dark-Assassin »

Thanks. With a little tweaking to use fixed point numbers, I got this to work perfectly.

Return to “Scripting”