Creating a math "loop"

72 Views Asked by At

Forgive me if I'm asking this question incorrectly, but I think I've hit the end of my mathematics knowledge on this one.

I'm trying to create an equation for video games that takes the desired jump height and desired time spent in air, and returns the gravity and jump speed you need to accomplish that. Essentially for every "step" of the game, the vertical velocity is reduced by a certain amount (gravity), until it reaches 0 at the desired height. (E.g. 4 > 3.5 > 3 > 2.5...)

I feel the best way to do this would require some sort of "loop", which to my knowledge is impossible. In the end, I'd need something like:

j+(j-(g*1))+(j-(g*2))+(j-(g*3))...

but repeated over and over until j reaches 0. If this is possible I'd love to know. Or if there's any alternative I'm missing. Thanks for any help.

1

There are 1 best solutions below

4
On BEST ANSWER

From physics, we know that the jump time is $$ t=\frac{2v_0}{g}$$ and the jump height is $$ h=\frac {v_0^2}{2g}.$$ Thus give, $t$ and $h$, you want $$ v_0=4\frac{\frac {v_0^2}{2g}}{\frac{2v_0}{g}}=\frac{4 h}t$$ and $$ g=\frac{2v_0}t=\frac{8h}{t^2}$$