# How to calculate initial jump velocity for reaching specific height?

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?

-
If you know appropriate tags, please add them to the question. –  user1306322 Oct 28 '12 at 8:56
"a gravity vector that decreases player's position by G pixels every frame" -- Shouldn't it be the player's velocity you're decreasing? –  Rahul Oct 28 '12 at 9:23
Yeah, I meant that. Thanks. –  user1306322 Oct 28 '12 at 9:25

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.
Somehow the correct value is found using Sqrt(gh/2). I decrease velocity.Y by G each frame after adding H to it once. –  user1306322 Oct 28 '12 at 9:39