Jump to content
• Advertisement

Jumping Physics

This topic is 2939 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

I am currently working on a 2D platformer. I am trying to make jumping easier to control. What I would like is something where is you hold the jump button down longer, you jump higher. Like most 2D platformers, like Mario, have.

The problem with this is that I cant get it to look realistic. What I am doing now is I have a MAX_TIME that you can hold jump for. Then during this time period or until the jump button is released an upward acceleration is applied to the sprite. But this looks like it is floating up rather than jumping.

Here is my code so far:
 JumpTime -= gameTime.ElapsedGameTime.Milliseconds; if (JumpTime <= 0) { EndJump(); } if (IsJumping) Velocity.Y += -8 * time; if (CurrentObjectState == ObjectState.Air) { Position += Velocity * time + physicsManager.GravityOverTwo * time * time; Velocity += physicsManager.Gravity * time; } else { Position += Velocity * time; }

Does anyone have any advice on this? Or could someone point me to a good tutorial? Every tutorial I have found just has a fixed jump that isn't affected by how long the button is held down.

Share this post

Share on other sites
Advertisement
Start with a decent upward velocity.
Each frame subtract gravity from velocity.
If the jump button is held for that frame and the frame is below a certain fixed number, add some upward velocity (a fixed amount, not an acceleration) to counter-act its gravitational pull.
Add velocity to position.

This should work.

L. Spiro

Share this post

Share on other sites
You might also need midpoint sampling for collisions if things start to shake and bounce too much. Just approximate where the item would be after one half timestep and sample the pressures from there.

Share this post

Share on other sites

• Advertisement
• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• Advertisement

• Popular Now

• 13
• 30
• 9
• 16
• 12
• Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!