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(
    btVector3(0, 0, 0)  
_rigidBody = new btRigidBody(cameraRigidBodyCI);

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),   
btRigidBody::btRigidBodyConstructionInfo* rigidBodyCI = new btRigidBody::btRigidBodyConstructionInfo(
    btVector3(0, 0, 0)  
if (_rigidBody != nullptr){
    delete _rigidBody;
    _rigidBody = nullptr;
_rigidBody = new btRigidBody(*rigidBodyCI);

The Collision-Detection itself:

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?

  • \$\begingroup\$ I somehow managed to solve it... But honestly, I have no idea how. \$\endgroup\$
    – SpiRyu
    Commented May 4, 2016 at 20:12

1 Answer 1


It's possible the player object moves into a wall and the position is updated, then collision is detected and the players position is then corrected creating a "bouncing" effect. To correct this, compute your collisions prior to moving the player (or probably any object).


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .