Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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?

share|improve this question
    
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

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
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
    
I found the problem: my update method was incorrect, now it works with your formula as expected. –  user1306322 Oct 28 '12 at 10:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.