# Jumping Physics

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

## 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 on other sites
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.

This should work.

L. Spiro

##### 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.

1. 1
2. 2
Rutin
19
3. 3
khawk
19
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633771
• Total Posts
3013763
×