Getting notified when a collision occurs is very useful:
- Did a projectile or weapon score a hit?
- Did an actor enter an active area?
- Did an actor start falling?
Bullet uses the following concepts to handle collisions and contact:
- Contact Pair: two objects that may collide form a contact pair. This contact pair exists even if there is no collision. Here a synonym for contact pair is ‘manifold’.
- Contact Points: at any time two objects may have zero, one or more contact points.
After iterating the simulation, we can retrieve contact pairs and check the number of contact points. So we can tell whether two objects collided (contact points > 0) or lost contact (contact points == 0)
Colliding objects are returned as instances of btCollisionObject (which btRigidBody inherits from). The method used to return collision pairs (aka manifolds) can return a pair with zero contact points. Just because we have a pair doesn’t mean there’s a collision, or contact.
The following code fragment may be called after stepSimulation().
__________________________
int numManifolds = world->getDispatcher()->getNumManifolds();
for (int i=0;i<numManifolds;i++){
btPersistentManifold* contactManifold =
world->getDispatcher()->getManifoldByIndexInternal(i);
btCollisionObject* obA =
static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB =
static_cast<btCollisionObject*>(contactManifold->getBody1());
int numContacts = contactManifold->getNumContacts();
}
_________________________
You can also find information about the location of contact points. Check the Bullet Wiki tutorials for more information about collisions and collision filtering
Impact velocity
I find that impact velocity can be reliably retrieved right when the bodies collide – in the code fragment above, obA, obB thus store their velocity at the time of impact, right before applying restitution. This is convenient to evaluate damage (e.g. remove health points / apply a stunning effect etc… ) resulting from collisions.


Comments