# Why are my Box2D wheels slipping on ground?

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

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?

-
Hi, how you generated the ground? – user3334375 Feb 13 at 14:53

## 2 Answers

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.

-
So, in order for the vehicle to overcome the hill i should lower the friction? and increase the motor force? – wingleader Jul 11 '14 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.

-