btRaycastVehicle roll-over on sharper turns

Post Reply
stefanejro
Posts: 12
Joined: Sun May 20, 2018 6:57 pm

btRaycastVehicle roll-over on sharper turns

Post by stefanejro » Wed May 30, 2018 12:25 pm

Hi, I have a problem with btRaycastVehicle. Whenever there is a sharp turn left or right, my vehicle rolls over the roof and spins a few times, even when the speed is not that high. I know that it's probably more or less how the vehicle would react in a real world, but I'm working on an arcade game and would like to achieve a slightly different behaviour. I would like the vehicle to slip / drift when there is a sharper turn but not roll over the roof. Could you give me some insights on which parameters should I adjust in order to achieve it ? Currently I have the following setup:

Code: Select all

btScalar chassisMass(1000.f);
btVector3 chassisInertia(0.0f, 0.0f, 0.0f);
btCollisionShape* chassisShape = new btBoxShape(btVector3(0.5f, 0.3f, 1.0f));
tuning.m_suspensionStiffness = 20.f;
tuning.m_suspensionDamping = 2.3f;
tuning.m_suspensionCompression = 4.4f;
tuning.m_maxSuspensionForce = 16000;
chassisRigidBody->setDamping(0.2f, 0.3f);
groundRigidBody->setFriction(2.f);
btVector3 wheelDirection(0.0f, -1.0f, 0.0f);
btVector3 wheelAxis(-1.0f, 0.0f, 0.0f);
btScalar suspensionRestLength(.1f);
btScalar wheelRadius(0.5f);
vehicle->addWheel(btVector3(-0.5f, 0.f, -1.0f), wheelDirection, wheelAxis, suspensionRestLength, wheelRadius, tuning, true);
vehicle->addWheel(btVector3( 0.5f, 0.f, -1.0f), wheelDirection, wheelAxis, suspensionRestLength, wheelRadius, tuning, true);
vehicle->addWheel(btVector3(-0.5f, 0.f,  1.0f), wheelDirection, wheelAxis, suspensionRestLength, wheelRadius, tuning, false);
vehicle->addWheel(btVector3( 0.5f, 0.f,  1.0f), wheelDirection, wheelAxis, suspensionRestLength, wheelRadius, tuning, false);

User avatar
drleviathan
Posts: 533
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: btRaycastVehicle roll-over on sharper turns

Post by drleviathan » Wed May 30, 2018 3:22 pm

You could give the vehicle a lower center of mass (COM), which would make it harder to tip over. In fact, you could give it such a low COM that it will automagically right itself were it to actually flip. I can think of a few ways to do this. Which is easier depends on how you are supplying the CollisionShape for the RigidBody used for the vehicle.

In its local-frame the COM of the RigidBody is the origin in the CollisionShape's local frame. That is, if you were using a btConvexHullShape then the points of the hull are specified in the local-frame and the COM is at <0,0,0>. This suggests the first method:

(1) Use a btConvexHullShape and translate the hulls points "up" such that the origin in the shape's local frame is very low.

(2) If you're using an implicit convex shape like btBoxShape or btSphereShape then these shapes have the origin at their center by definition and cannot be moved. However, you can wrap convex shapes in a btCompoundShape and give them all "upward" translations such that the origin of the base shape is very low.

(3) If you're already using btCompoundShape then you just need to adjust the transforms of the subshapes accordingly.

Note: In the world-frame the COM of the RigidBody is its position in the world. Which means: if you offset the COM to be "low" in the local-frame, you will need to supply an inverse local-frame transform when using the RigidBody's world-frame transform to place your GameObject correctly on the render side.

stefanejro
Posts: 12
Joined: Sun May 20, 2018 6:57 pm

Re: btRaycastVehicle roll-over on sharper turns

Post by stefanejro » Thu May 31, 2018 9:34 am

Oh, that looks very promising. I will try it out soon. Thanks dr. Leviathan !

stefanejro
Posts: 12
Joined: Sun May 20, 2018 6:57 pm

Re: btRaycastVehicle roll-over on sharper turns

Post by stefanejro » Sat Jun 02, 2018 11:18 am

I ended up using btCompoundShape and setting the origin to -0.4. Works like a charm :D Thanks dr. Leviathan !

Code: Select all

btCompoundShape* compound = new btCompoundShape();
btTransform localTrans;
localTrans.setIdentity();
localTrans.setOrigin(btVector3(0,-0.4,0));
compound->addChildShape(localTrans,chassisShape);

Post Reply