4

I am trying to use bullet physics library in my opengl game engine for collision detection.

I am not trying to do anything complicated, I only want to know when things collide in the 3d world. I am only using box shapes and I have no interest in moving the objects using physics (I have even disabled collision response for my rigid bodies).

I have managed to get the collision to work doing the following:

  • First, each frame I update the rigid bodies world transform based on the entity's transform it is attached to. For example I move my player right, the rigid body (and the bounding box) moves with me.

  • I am checking if 2 objects are colliding using this code:

    void PhysicsManager::myTickCallback(btDynamicsWorld *world, btScalar timeStep)
    {
        int numManifolds = world->getDispatcher()->getNumManifolds();
        if (numManifolds > 0)
            cout << "COLLISION" << endl;
    }
    

myTickCallback is the dynamics world internal tick call back: dynamicsWorld->setInternalTickCallback(myTickCallback);

What is weird now is that when I start up the game, I move my player on the other object I want it to collide with and it starts spamming COLLISION. If I leave the player on the object it will keep spamming it. However, if go away from the object and go back into it several times, after a while it just stops writing COLLISION.

I have checked if the rigid bodies are moving (if there is collision response) and there isn't.

This could be a problem in the game I am trying to create because I want the player to be hit by projectiles and it wouldn't be right if he stops getting hit after a while.

Claudio
  • 10,614
  • 4
  • 31
  • 71
456panos
  • 55
  • 2

0 Answers0