Vehicle weirdness

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
redwyre
Posts: 1
Joined: Mon Jul 07, 2014 3:41 pm

Vehicle weirdness

Post by redwyre »

I copied some of the vehicle code however after I adjusted it to fit the model I have, it's acting strangely and I don't understand why.

Changing the settings seems to either result in the wheels penetrating the ground (and the body penetrating with other physics objects under it), or the car tipping over or even flipping upside down. I'm wondering if anyone has had experience playing with the vehicle controller that might be able to shed some light on what's happening?

If I increase the weight to something realistic (>800kg) the wheels will be under the ground, and any smaller objects will be sandwiched between the car and the ground. This is confusing because it shouldn't happen in any case?

Here is an image of the car (orange boxes are the physics objects, axes are centre points).

Image

And the relevant code:

Code: Select all

            var carBody = new Box(pos.ToBP(), 2.2f, 0.8f, 5.0f, 6.0f);
            carBody.CollisionInformation.LocalPosition = new BEPUutilities.Vector3(0.0f, 0.4f, 0.0f);

            vehicle.VehiclePhysics = new Vehicle(carBody);
            float stiffness = 1000.0f;
            float dampening = 100.0f;
            //float maxSpringCorrectionSpeed = 10000000.0f;

            float radius = 0.38f;
            float widthFront = 0.25f;
            float widthBack = 0.4f;
            float suspensionLength = 0.2f;
            float wheelHeight = -0.4f;

            // front left
            Vector3 attachPoint;
            attachPoint = new Vector3(-0.93f, wheelHeight, -1.8f);
            var wheelFrontLeft = new Wheel(
                new CylinderCastWheelShape(radius, widthFront, localWheelRotation, wheelGraphicRotationLeft, false),
                new WheelSuspension(stiffness, dampening, BEPUutilities.Vector3.Down, suspensionLength, attachPoint) { /*MaximumSpringCorrectionSpeed = maxSpringCorrectionSpeed*/ },
                new WheelDrivingMotor(2.5f, 30000, 10000),
                new WheelBrake(1.5f, 2, .02f),
                new WheelSlidingFriction(4, 5));
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Vehicle weirdness

Post by Norbo »

Changing the settings seems to either result in the wheels penetrating the ground...
If I increase the weight to something realistic (>800kg) the wheels will be under the ground...
Wheels penetrating the ground is probably caused by the suspension's strength being insufficient to fight compression. Note that the suspension does not become rigid when it bottoms out, but rather keeps applying only as much force as it can based on the resting suspension length. Some potential workarounds:
1) Increase suspension stiffness/damping such that the suspension doesn't bottom out as frequently.
2) Move suspension anchor further up into the car, increase suspension length to compensate. Result is that the wheel will continue to travel up until the ground gets stopped by the car body.
3) The inverse of #2: add some geometry to the car to make the car rigidly bottom out first.
4) Make the suspension go near-rigid when it bottoms out. One simple hacky way to do it: monitor the wheel.Suspension.CurrentLength and bump up the wheel.Suspension.SpringSettings.Stiffness/Damping when it gets close to zero.
or the car tipping over or even flipping upside down.
This might be related to the body LocalPosition; that changes the position of the collision object relative to the center of mass. If the center of mass is very high (or very low, below the ground) relative to the collision geometry, the vehicle would easily topple.
If I increase the weight to something realistic (>800kg), ... any smaller objects will be sandwiched between the car and the ground. This is confusing because it shouldn't happen in any case?
In addition to the above issues with suspension being too weak to support the car, that kind of mass is also likely to run into mass ratio issues. An entity with 800 mass resting rigidly on an entity with 10 mass will result in the light object getting squished. That sort of configuration is very hard for the solver to find a solution to. (A light object resting on a heavy object is perfectly fine.)

In most rigid body game physics solvers, these sorts of high mass ratio conditions- either from a really heavy object resting on a light object, or a heavy object hanging on a light chain of constraint-connected entities, or otherwise- result in either explosive instability or squishiness depending on the constraint configuration. BEPUphysics chooses squishiness by default in most cases.

The standard recommendation is to avoid extreme mass ratios. Staying below a ratio of 10:1 is a good idea- the smaller the ratio, the better.

Code: Select all

float widthBack = 0.4f;
When extrapolating the rest of the wheels to test the configuration, I noticed that the back wheels extended outside of the vehicle's body. When the car brushes up against an object on the side, the wheel could jump up strangely. To avoid this, ensure the wheel is fully contained within the car body (maybe by adding additional geometry if necessary).

Finally, there are alternatives to the Vehicle class. Cars constructed purely from entities and standard constraints tend to work pretty well and can behave more naturally in some cases at the cost of a bit more CPU time. Check out the TankDemo, SuspensionCarDemo, SuspensionCarDemo2, and the ReverseTrikeDemo in the BEPUphysicsDemos for examples.
Post Reply