1
\$\begingroup\$

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?

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$

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