Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a car, set up in Box2D as a rectangle connected with two wheels using WheelJoints:

image of car trying to go uphill

The wheels are defined as follows:

    FixtureDef wheelFixtureDef = new FixtureDef();
    wheelFixtureDef.density = 1.f;
    wheelFixtureDef.shape = wheelShape;
    wheelFixtureDef.friction = 0.98f;
    wheelFixtureDef.restitution = 0.3f;


    // wheel joint (only one of the wheels has the motor enabled)
    wheelJointDef.dampingRatio = 0.9f;
    wheelJointDef.frequencyHz = 20.0f;
    wheelJointDef.motorSpeed = 15.4f;
    wheelJointDef.maxMotorTorque = 100.f;

And the ground:

    FixtureDef groundFixtureDef = new FixtureDef();
    groundFixtureDef.density = 0.f;
    groundFixtureDef.friction = 1.0f;

Still, when trying to climb that hill in the picture, the wheels reach a stage where they just keep slipping, and it slides back down.

Why does it slip even though the friction coefficients are set high? How can I make it overcome that hill?

share|improve this question

2 Answers 2

Your car is slipping for the same reason that a car hanging up-side down, riding the ceiling, with 100% friction would slip. 100% friction roughly means that 100% of the force exerted via the wheels on the terrain is used to counter movement perpendicular along the normal of the terrain. But this force still isn't enough to counter the force of gravity. This happens when the forces working up-on the vehicle that direct downwards are larger than those pointing towards the ground. You'll probably see wheel slippage starting from hills with a 45 degree slope.

You could solve this by 'faking' gravity always having it point in the opposite direction as the normal of the terrain segment the vehicle is currently driving on.

share|improve this answer
    
So, in order for the vehicle to overcome the hill i should lower the friction? and increase the motor force? –  wingleader Jul 11 at 16:24

Friction coefficient is equal to tangent of the maximum angle before the item will slide.

You need to set coefficient greater then 1. There is a function in the Settings class - MixFriction. It's used to calculate the friction coefficient between surfaces, by default it's a geometric mean, you can change this too.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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