so that any other vehicle wouldn't respond to collision with removed vehicle.
Here's what I did.
Code: Select all
if (mRigidBody)
{
auto motionState = mRigidBody->getMotionState();
if (motionState) delete motionState;
physicsWorld->removeRigidBody(mRigidBody);
delete mRigidBody;
mRigidBody = nullptr;
}
if (mVehicle)
{
physicsWorld->removeVehicle(mVehicle.get());
mVehicle.reset(); // unique_ptr, this is bad, no point in using smart pointer..
mVehicleRayCaster.reset(); // unique_ptr, this is bad, no point in using smart pointer..
}
But since rigidbody can be created and destroyed several times, I want to optimize it by minimizing new/delete calls.
I tried to use only physicsWorld->removeRigidBody and physicsWorld->removeVehicle, and delete memory when program terminated or in specific condition.
But vehicle still respond to removed vehicle..
How to correctly remove vehicle/rigidbody from dynamics world without deleting rigidbody/motion state..