HOWTO 4 wheel vehicle

From ODE Wiki
Jump to: navigation, search

Good examples of making working vehicles are Jon Watte's carworld and raycar. You could maybe flesh out this article using those two. Raycar is the simplest.


If you came here, you probably already know that building a working vehicle in ODE isn't that easy. Maybe you notice that the wheels have trouble turning when rotating at high speeds? Maybe you encountered the lostop/histop bug in ODE 0.5. Maybe you noticed your vehicle flips over when turning, when going at moderate speeds?

All this is because ODE is a pretty accurate simulator. Here's a hint: Implement the same workarounds that have been put in real cars.

Stop rolling over

To stop rolling over in high speed turns, make sure that you:

  1. Implement force-dependent slip. See the slip1 and slip2 parameters of a contact surface.
  2. Reduce the tyre/road friction. Use low values in the mu and mu2 fields of a contact surface.
  3. Keep the center of mass for the chassis low, wrt the wheel bodies.

If you do all this, and your car still rolls over, you can consider implementing "anti-sway bars". In real vehicles, these were bars that linked each opposite suspension, so that when one side is pressed down (when going in a curve), it also pressed down on the suspension on the other side. This prevents the car from tilting over too much.

This is an example of how to compute the force adapted from the OgreVehicle class assuming 4 wheels:

void applyAntiSwayBarForces() {
    amt = 0;
    for(int i = 0; i < 4; i++) {				
        Vector3 anchor2 = wheels[i].Joint.Anchor2;
        Vector3 anchor1 = wheels[i].Joint.Anchor;
        Vector3 axis = wheels[i].Joint.Axis2;
        displacement = Vector3.Dot(anchor1-anchor2, axis);
        if(displacement > 0) {
            amt = displacement * swayForce;
            if(amt > swayForceLimit)
                amt = swayForceLimit;
            wheels[i].Body.AddForce(-axis *amt); //downforce
            wheels[i^1].Body.AddForce(axis *amt); //upforce

Check the FAQ

The FAQ addresses many issues that might arise in a car simulation, like wheels getting stuck in geoms, or numerical errors in the hinge constraints. Be sure to check it.