I'm using Bullet Physics for Collision Detection in a first person game. The collision basically work fine, I cannot walk through objects. But if I walk against the wall and release the key I get bounced back and automatically move backwards. This is something I do not want. The player should not be bouncing off when walking into a wall, it just shouldn't be possible to pass through it.
Here are some code snippets.
Creating the Player-RigidBody (class Camera):
btCollisionShape* _collisionShape = new btCapsuleShapeZ(0.2f, 1.0f);
btDefaultMotionState* _motionState = new btDefaultMotionState(btTransform(
btQuaternion(1, 0, 0, 1),
btVector3(_position.x, _position.y, _position.z)
));
btRigidBody::btRigidBodyConstructionInfo cameraRigidBodyCI(
10,
_motionState,
_collisionShape,
btVector3(0, 0, 0)
);
_rigidBody = new btRigidBody(cameraRigidBodyCI);
_rigidBody->setActivationState(DISABLE_DEACTIVATION);
Creating the RigidBody of the Walls and other box-objects:
btVector3 rigidBodyPos;
btCollisionShape* collisionShape;
glm::vec3* minMax = getMinMaxVertexCoords();
glm::vec3 minCoords = minMax[0];
glm::vec3 maxCoords = minMax[1];
glm::vec3 middleSize = glm::vec3((maxCoords.x - minCoords.x) / 2, (maxCoords.y - minCoords.y) / 2, (maxCoords.z - minCoords.z) / 2);
glm::vec3 middlePos = glm::vec3((maxCoords.x + minCoords.x) / 2, (maxCoords.y + minCoords.y) / 2, (maxCoords.z + minCoords.z) / 2);
collisionShape = new btBoxShape(btVector3(middleSize.x, middleSize.y, middleSize.z));
rigidBodyPos = btVector3(middlePos.x, middlePos.y, middlePos.z);
btMotionState* motionState = new btDefaultMotionState(btTransform(
btQuaternion(0, 0, 0, 1),
rigidBodyPos
));
btRigidBody::btRigidBodyConstructionInfo* rigidBodyCI = new btRigidBody::btRigidBodyConstructionInfo(
0,
motionState,
collisionShape,
btVector3(0, 0, 0)
);
if (_rigidBody != nullptr){
delete _rigidBody;
_rigidBody = nullptr;
}
_rigidBody = new btRigidBody(*rigidBodyCI);
_rigidBody->setActivationState(DISABLE_DEACTIVATION);
_rigidBody->setRestitution(0.0f);
The Collision-Detection itself:
dynamicsWorld->updateAabbs();
dynamicsWorld->stepSimulation(1 / 60.f, 10);
//...
btTransform cameraTrans = camera->getRigidBody()->getWorldTransform();
camera->setPosition(glm::vec3(cameraTrans.getOrigin().getX(), cameraTrans.getOrigin().getY(), cameraTrans.getOrigin().getZ()));
How can I change this behaviour?