Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This question already has an answer here:

I'm developing game in marmalade sdk in c++. I have player in the area.and I wanna make him jump when i pressed a button.When I use this player.moveUp(5px); it just go up 5px, but he has to fall down back. so that when i use these: player.moveUp(5px); and player.movedown(5px); it do nothing.Because the fps is 30 and it's performing so fast. how i can fix that?

share|improve this question
add comment

marked as duplicate by Sean Middleditch, Tetrad Feb 18 '13 at 23:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

Jumping is an operation that you need to have take effect over time, not an instantaneous modification to the player location. To make a realistic jump, you're going to want to take into account:

  • Velocity
  • Gravity (an acceleration downward)
  • Time
  • Player height (i.e., y coordinate)

The relationship between these will be something like this:

pos_y = pos_y + (velocity_y * time_difference) + (gravity_y * (time_difference ^ 2) / 2) velocity_y = velocity_y + (acceleration_y * time_difference)

(That formula is taken from an answer on impulsed jumping.)

The gravity is a constant acceleration downard, which is constantly modifying the velocity. So the velocity starts out going up, and gets pulled progressively downward. The change in time (delta) is used to determine how far along the process we are.

share|improve this answer
add comment

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