I need a way to detect when a dynamic rigid body hits the player of my game, which is a kinematic body.
Curently just after the stepsimulation call, I search all contact manifolds to try to find the collision. I identify the rigid body associated to the player by the userpointer. The thing is that I'm not always getting that there is a hit, when I can see that there was one.
I was thinking that also to the collision objects we could add like a callback class the is called when a collision is made
The code that I'm currently using is:
btPersistentManifold* contactManifold = m_dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
for (int j=0;j<numContacts;j++)
{
btManifoldPoint& pt = contactManifold->getContactPoint(j);
...
}
Callback for collision
-
- Posts: 2
- Joined: Fri Jul 13, 2007 2:49 pm
-
- Posts: 14
- Joined: Thu Jun 28, 2007 2:26 pm
Collision Callback
What you will want to do is register a callback.
Firs
Next, register it intothe dispatcher...
Now, whenever two things hit, the callback is called, and you can see exactly what hit.
Firs
Code: Select all
public void CollisionCallback(ref BroadphasePair collisionPair, CollisionDispatcher dispatcher, DispatcherInfo dispatchInfo)
{
int i = 3;
CollisionObject collisionObjectA = collisionPair.ProxyA.ClientData as CollisionObject;
CollisionObject collisionObjectB = collisionPair.ProxyB.ClientData as CollisionObject;
// collision stuff
Code: Select all
_collisionDispatcher = new CollisionDispatcher();
_collisionDispatcher.NearCallback += CollisionCallback;
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA