# 2D Platformer Jumping Problems

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

## Recommended Posts

In the 2D platformer I'm working on, the jumping feels bad and I'm not sure if my variables are set poorly, or if the design I'm using is a bad choice. When I jump, the player jumps up very quickly, and then falls at a slower rate. Ideally I'd want the jump and fall to feel like they're the same speed.

Currently, to jump I'm applying an impulse, and then letting gravity take over. To slow the jump speed down I tried increasing the gravity but then the falling speed doesn't feel good. When I try to lower the magnitude of the impulse, I can't get the desired jump height. It seems like every time I try tweaking one variable to fix a problem it produces some other undesirable result. I guess what I want is to maintain the current jump height, but also have the jumping speed be slowed so that it's equal to the falling speed (gravity). Am I taking entirely the wrong approach here?

If you want to see what I'm talking about you can download the "game" here: http://www.mediafire...jfn3jdxvc5nvspq, enter is start, arrows move, x is jump

Here is the code to calculate position:
 void CPhysicsController::update(double time) { ddx_ = forceX_ / mass_; ddy_ = forceY_ / mass_; dx_ += ddx_; dy_ += ddy_; float linearDamp = -0.15f; dx_ += (dx_ * linearDamp); dy_ += (dy_ * linearDamp); x_ += (time * dx_); y_ += (time * dy_); } void CPhysicsController::applyForce(float forceX, float forceY) { forceX_ += forceX; forceY_ += forceY; } void CPhysicsController::applyImpulse(float impulseX, float impulseY) { dx_ += impulseX; dy_ += impulseY; } 

For gravity I do this:
 if (physicsControllers_->isOnGround() == false) { physicsControllers_->applyForce(0.0f, 70.0f); } 

And for jumping, I do this:
 if (physicsController_->isOnGround() == true) { physicsController_->applyImpulse(0.0f, -2000.0f); } 

##### Share on other sites
You could have your physics engine check whether or not the player is currently jumping, and then only apply gravity if they're not
That way, you could set the force of gravity and your impulse force how you want and they wouldn't affect each other

##### Share on other sites
 dx_ += ddx_; dy_ += ddy_; [/quote]

Do you mean this?
 dx_ += time*ddx_; dy_ += time*ddy_;

It looks like your linear damp might be too large. If you set it to zero, your jump should be completely symmetric.

##### Share on other sites

 dx_ += ddx_; dy_ += ddy_; 

Do you mean this?
 dx_ += time*ddx_; dy_ += time*ddy_;

It looks like your linear damp might be too large. If you set it to zero, your jump should be completely symmetric.
[/quote]

You're right, I set it to 0.0001 and it felt much better jumping, and I also scaled the acceleration by time.

But When I set it too low things move too fast and get slippery. Or maybe this is just because I need to implment friction/air resistance?

##### Share on other sites
Well, what you had there was some for of air resistance, but perhaps it was too much, so it felt like jumping in molasses. If your character is sliding on the floor, you need to implement friction.

##### Share on other sites

Well, what you had there was some for of air resistance, but perhaps it was too much, so it felt like jumping in molasses. If your character is sliding on the floor, you need to implement friction.

Ah, I see. But then doesn't the problem exist that given enough time in the air, with such a low linearDamp value, the player would be able to get to very high velocities? Or maybe I should just keep playing around with it to see if I can find a good balance.

##### Share on other sites
Yes, the balance thing. The terminal velocity of a human body is about 56m/s according to Wikipedia. If you want realism, you can set your drag to match that. However, drag is primarily quadratic in the speed of the object, not linear.

Or you could ignore physical reality and do whatever feels right in your game, perhaps including a hard speed limit for falling characters. You need to experiment until you get the feeling you want.

##### Share on other sites
Yes, the balance thing. The terminal velocity of a human body is about 56m/s according to Wikipedia. If you want realism, you can set your drag to match that. However, drag is primarily quadratic in the speed of the object, not linear. Or you could ignore physical reality and do whatever feels right in your game, perhaps including a hard speed limit for falling characters. You need to experiment until you get the feeling you want.

Thank you so much for the help! I came up with a solution I'm happy with. I took some time to play the games that are an influence on what I'm trying to make and I realized the player characters actually don't even really use acceleration when they move, just a constant velocity. I think if I were to write a platformer where you can't change direction in an instant it would be frustrating so what I did was add a movement vector that sets a constant velocity and in my update function I added them like so:

 x_ += (time * (dx_ + movementX_)); y_ += (time * (dy_ + movementY_)); 

So I can still apply external forces like gravity, or a gust of wind, or standing on a conveyor belt or someting, but also have the option to move with a constant velocity as well.

In case anyone's interested here's a compiled version with my changes: http://www.mediafire...14lk6gaplgu69zi. There's still a few bugs to work out but I think the biggest hump has been passed. Thanks again!

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

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

• Total Topics
633757
• Total Posts
3013711
×

## Important Information

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!