1
$\begingroup$

I'm making a game engine and it's time to make realistic jumps. My problem is I can't figure out what jump velocity to set for the player.

There is a gravity vector that decreases player's velocity by G pixels every frame, and the initial jump vector J that only adds to the total momentum once, when the player jumps. I want to be able to simply set a number of pixels for how high the character will jump. How do I make that formula?

  • 0
    Yeah, I meant that. Thanks.2012-10-28

1 Answers 1

4

If at each frame you do $y=y+v_y$ and $v_y = v_y-g$ and start with $v_y=v_0$, then the top will be reached after $\frac{v_0}g$ frames and a height difference of $\frac{v_0^2}{2g}$. Thus to jump a height $h$, you need $v_0=\sqrt {2 g h}$. Some minor adjustment may be necessary dpending on your needs if $v_0$ is not a multiple of $g$, i.e. if the top is reached between two frames.

  • 0
    I found the problem: my update method was incorrect, now it works with your formula as expected.2012-10-28