Any help on how to destroy the vehicles is a plus for me right now.
Here is the ugly way I am doing it right now, and i know its probably horribly wrong..
(*it) is our own vehicle class that holds:
btRigidBody* mVehicleChasis;
btRigidBody* mVehicleWeapon;
btSliderConstraint *mWeaponSlider;
btVehicleRaycaster* mVehicleRaycast;
btRaycastVehicle* mVehicle;
Code: Select all
////////////========================Destroy chassis============================
{
btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[(*it)->miID];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->getMotionState())
{
while(body->getNumConstraintRefs())
{
btTypedConstraint* constraint = body->getConstraintRef(0);
dynamicsWorld->removeConstraint(constraint);
delete constraint;
}
delete body->getMotionState();
dynamicsWorld->removeRigidBody(body);
}
else
{
dynamicsWorld->removeCollisionObject( obj );
}
delete obj;
}
//====Destroy weapon====================================
// the weapon body is a slider constraint attached to the chassis
{
btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[(*it)->miWeaponID];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->getMotionState())
{
while(body->getNumConstraintRefs())
{
btTypedConstraint* constraint = body->getConstraintRef(0);
dynamicsWorld->removeConstraint(constraint);
delete constraint;
}
delete body->getMotionState();
dynamicsWorld->removeRigidBody(body);
}
else
{
dynamicsWorld->removeCollisionObject( obj );
}
delete obj;
}
dynamicsWorld->removeAction((*it)->mVehicle);//same as removeVehicle
///////////============================================================
Then in our vehicle object's destructor we have
delete mVehicleRaycast;
delete mVehicle;
any help or rewrite would be helpful.
thank you.