Game Mechanics Calculating the velocity needed to reach a specific jump height

T

Tirous

Guest
I'm making a game right now, and I'm just about finished building the physics engine.

All I need now is a way to find the velocity needed to accelerate an entity upwards by, so that, assuming gravity is non-zero and going against the entity, its vertical velocity will reach zero when it has gone exactly the amount of distance into the air that I want it to travel before peaking.

The problem is that I have next to no idea how to do the above. I've tried all manner of different things; all manner of maths; reading up on projectile motion, terminal velocity, etc. Yet I still have little to no idea how to solve this.

The main problem for me is that gravity is a constant acceleration, and doesn't grow linearly as time passes, instead compounding upon itself, maintaining all previous applications while still adding more. This aspect REALLY confuses me... :(

So ya, do any of ya'll know how to do the above?
 
A

Agreeable

Guest
v² = u² + 2as

v = current vertical velocity
u = initial velocity (jump velocity)
a = acceleration (gravity)
s = distance

Say (as an example) gravity is -9.8ms² and the required jump height is 2 metres.

v²=u²+2as
0 = u² + 2as
-2as = u²
u² = -2as

u² = -2 * -9.8 * 2
u² = 39.2
u = 1.788854381999832

Then you probably want to flip the sign as we are in screen space for normal 2D games.


*Edit*
You'll want to multiply the result with the amount of pixels per metre in your game too.
 
Last edited by a moderator:
Top