My vehicle tires are not at each corner of the chassis. The front of the vehicle has the wheels slightly pushed back which makes the whole chassis lean down from the back to the front (as I would except).
How would I go about changing the center of mass from the direct center of the chassis (as in "car 1" to the center of the wheels (as in car 2)? The following picture shows what I mean (sorry for the paint diagram, but it is the reason I am a programmer).
It is my understanding that I need to change the origin for the chassis shape of the compound shape in order to do this but whenever I do the whole chassis simple translates relative to the wheels and I still see the same problem. I assume I am just missing something here.
Code: Select all
btCollisionShape * chassisShape = new btBoxShape(btVector3(0.5f, 0.4f, 0.625f));
btCompoundShape * compound = new btCompoundShape();
btTransform localTrans;
localTrans.setIdentity();
//localTrans effectively shifts the center of mass with respect to the chassis
//LINE OF INTEREST
/****************************************************
*****************************************************
*****************************************************
//Doesn't seem to actually change the way the vehicle "leans" with
localTrans.setOrigin(btVector3(0, 0.4, 0.3));
//Or
localTrans.setOrigin(btVector3(0, 0.4, -0.3));
//It just changes how it is displayed relative to the wheels
*****************************************************
*****************************************************
*****************************************************/
compound->addChildShape(localTrans, chassisShape);
btTransform tr;
tr.setIdentity();
tr.setOrigin(btVector3(0, 0, 0));
carChassis = CreateRigidBody(vehicleMass, tr, compound);
carChassis->translate(btVector3(0.0, 1.0, 0.0));
//create vehicle
vehicleRayCaster = new btDefaultVehicleRaycaster(BulletPhysicsSystem::getSingleton().GetWorld().get());
vehicle = new btRaycastVehicle(tuning, carChassis, vehicleRayCaster);
//never deactivate the vehicle
carChassis->setActivationState(DISABLE_DEACTIVATION);
BulletPhysicsSystem::getSingleton().GetWorld()->addVehicle(vehicle);