contactPointCallback being called twice for dynamic objects

contactPointCallback being called twice for dynamic objects

Bild des Benutzers Bobby M.

Hello!

I'm using a class derived from hkpContactListener and implimenting the contactPointCallback() method, and I've run into a problem. At first, I was only paying attention to contact types of TYPE_TOI, because I was under the impression that they were the only "important" collisions. But then I realized that two dynamic objects of normal priority do not generate TYPE_TOI contacts, so I started monitering both types TYPE_TOI and TYPE_MANIFOLD.

So far, it seems to be working okay, except for one problem. The callback seems to be getting called twice for every one collision between two dynamic objects. During these two calls, everything in the callback event seems to be identical (the objects, the time stamp, the impact velocity, etc). I'm wondering if there is something I'm doing incorrectly that is making this happen? Or perhaps something I can do to disable it? Currently, my only solution is to record pointers to the last two colliding objects along with the time stamp, and ignore the second of the two identical callbacks by comparing those three things.

If anyone can shed some more light onto this for me, or has a better solution, I would really appreciate it.
Thank you!

3 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Bild des Benutzers Bobby M.

I just noticed that the hkpContactPointEvent::m_source variable changes from SOURCE_A to SOURCE_B between the two identical callbacks. I'm assuming then that this is happening because both objects have this listener added to them, so an event is being triggered for each. Is there any way to disable this? To only receive callbacks for each pair of objects once?

If an object that has a listener added collides with one that doesn't have a listener added, will the source always be SOURCE_A? Would the solution be to simply ignore all callbacks from SOURCE_B? Or would that cause me to possibly ignore collisions with objects that have listeners attached?

Thanks again, any advice is appreciated.

Bild des Benutzers Havok - Josh S.

Hi Bobby,

An hkpContactListener can be added to an hkpEntity or to the hkpWorld. When it's added to an entity, it will fire once for every contact involving that entity, meaning it will fire twice if it is added to both entities in contact. When it's added to the world, it will fire once for each collision in the world. It sounds like you want the functionality of adding your contact listener to the world.

This is related to the SOURCE values you are getting. Contact point callbacks are designed to be symmetrical, so a particular rigid body could be either SOURCE_A or SOURCE_B. This value indicates which entity was responsible for firing the callback (for a world callback the source will be SOURCE_WORLD).

Josh S. Havok Developer Support Engineer www.havok.com

Melden Sie sich an, um einen Kommentar zu hinterlassen.