0
我試圖實現一個簡單的門,當玩家靠近時就會消失。問題在於,即使從世界移除後,門仍然阻止玩家。從子彈物理世界移除後剛體仍然發生碰撞
在每一個幀中,我執行以下操作:
蜱模擬
迭代通過所有的碰撞
如果放置在播放器和一個傳感器對象之間的碰撞靠近門,用這種方法取出門:
self.dynamicsWorld->removeCollisionObject(object.collisionBody);
奇怪的是,這對我的場景中的拋射物非常適用,一旦它們與任何其他物體接觸就會被移除。
這裏的世界是如何設置的:
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));
而這裏的門是如何設置的:
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);
我已經嘗試過這個對象上禁用停用,並使其AA動態沒有質量的對象,但結果是一樣的。
那麼如何從世界中移除一個靜態對象並使其工作?