0

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.

  • What do you mean by "for every step of the game"? – littleO Jun 09 '17 at 06:52
  • In video game terms, basically the unit of time the game runs on. So a ball would move at 20 pixels per step. – Ec Little Jun 09 '17 at 07:00
  • So the time can be seen as a discrete variable $i$ that takes value from $0$ to,say, $n-1$. Then at time $i=0$ you height is $A$, then you want that at time $n-1$ it is $B$. Hence $height(i) = (A-B)/(i+1)$. – Zubzub Jun 09 '17 at 07:06

1 Answers1

4

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}$$