In my engine i need to detect which body part is hit by an object to get different damage values per body parts. This would be easily done if i could detect which child shape (or child shape index) was hit inside the compound shape, but i am not finding an easy way to do it.
The collision detection is done via iterating the manifold and get the correct pair:
Code: Select all
for (int i = 0; i < numManifolds; i++)
{
btPersistentManifold* contactManifold = dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
btCollisionObject* obA = (btCollisionObject*)(contactManifold->getBody0());
btCollisionObject* obB = (btCollisionObject*)(contactManifold->getBody1());
int numContacts = contactManifold->getNumContacts();
if (numContacts > 0)
{
// If object B is an humanoid
if (obB->getUserIndex() == 1)
{
for (int j = 0; j < numContacts; j++)
{
btManifoldPoint pt = contactManifold->getContactPoint(j);
std::cout << "Index0: " << pt.m_index0 << std::endl;
std::cout << "Index1: " << pt.m_index1 << std::endl;
std::cout << "Index0: " << pt.m_partId0 << std::endl;
std::cout << "Index1: " << pt.m_partId1 << std::endl;
}
}
}
}
If i print these numbers it gives me random/gibberish results but shouldnt this be the direct indices as explained here?
https://www.bulletphysics.org/Bullet/ph ... =9&t=10617
Many thanks,
André