I'm attempting to implement a simple door which just disappears when the player gets close. The problem is, the door is still blocking the player even after bering removed from the world.
On every frame, I do the following:
Tick the simulation
Iterate through all collisions
If there is a collision between the player and a sensor object placed close to the door, remove the door using this method:
self.dynamicsWorld->removeCollisionObject(object.collisionBody);
The strange thing is, this works perfectly for removing projectiles in my scene, which are removed once they have contact with any other body.
Here's how the world is set up:
btDefaultCollisionConfiguration* collisionConfiguration;
btCollisionDispatcher* dispatcher;
btBroadphaseInterface* overlappingPairCache;
btSequentialImpulseConstraintSolver* solver;
btDiscreteDynamicsWorld* dynamicsWorld;
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
overlappingPairCache = new btDbvtBroadphase();
solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0, 0, gravity));
And here's how the door is set up:
float mass = 0;
bool isDynamic = false;
btBoxShape* shape = new btBoxShape(size);
btTransform transform;
transform.setIdentity();
btVector3 localInertia(0, 0, 0);
if (isDynamic) {
shape->calculateLocalInertia(mass, localInertia);
}else{
mass = 0;
}
btDefaultMotionState* motionState = new btDefaultMotionState(transform);
btRigidBody::btRigidBodyConstructionInfo cInfo(mass, motionState, shape, localInertia);
btRigidBody* body = new btRigidBody(cInfo);
btTransform transform;
body->getMotionState()->getWorldTransform(transform);
transform.setOrigin(position);
body->getMotionState()->setWorldTransform(transform);
self.dynamicsWorld->addRigidBody(body);
I have already tried disabling deactivation on this object, and making it a a dynamic object without mass, but the result is the same.
So how do I remove a static object from the world and actually make it work?