Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Jumping/Falling Velocity Physics

I'm horrible at physics, so I'm failing on this part. I want my object to start moving upwards on the Y-axis starting at the maximum peak rate, then gradually decreasing in velocity before it starts going back down in a natural curve as it would be in real life you wanted to jump. I just want the formula. The maximum fall velocity should be at 9.8, and the velocity will always be a float value.

First the variables that I use now:
Code:
float Velocity;

float Gravity;
The velocity value is the actual movement on the sprite that is subtracted on the Y-axis for the object. The gravity is set to a negative 9.8. The velocity starts at 9.

The handling of the velocity as soon as the jump occurs is like this right now (but it does not generate a smooth curve and does not compute as intended because I suck at physics):
Code:
if(!Jump){ Velocity = 9f; Jump = true; }

else if(Velocity <= Gravity){ Velocity = Gravity; }

else{ Velocity += (Velocity - Gravity) }
It creates a really weird curve on the jump. I want a smoother curve.

Is there any formula that would allow this to be done a lot simpler and smoother than I am currently doing it with my lack of physics skills?

For reference, this is XNA 4.0 in C#.

Thanks in advance!
 
Are you using a vector or horizontal and vertical velocity?


Pretty simple but this should work.
Code:
 

Y_Velocity -= Gravity/Graphics.framerate

if (Y_Velopcity > GravityMax)

  Y_Velocity = GravityMax

 
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top