ContactListener and Collision Filters

Hi, apologies if this has been asked elsewhere, but I have a question about Contact Listeners and CollisionFilters. I have a situation where I have two objects which can collide with the world but not with each other ( each has categoryBits and maskBits set to ignore the other). I'd like to be able to join the two of them if they collide, specifically if they overlap. I've set up Collision Filters, but unless I am missing something or have done something wrong, it seems like contact between objects with matching filter categoryBits and maskBits are not reported by the ContactListener? i guess i am asking if the contact is ignore entirely, or just not reported by the ContactListener. If i want to check for these types of collisions, what is the best way for me to do this? i can always do a simple hit test, but since that is probably an n-squared speed process, I was hoping for something smarter / more elegant.

Thanks
If you want to detect the collision, you should not filter it away.

I suppose your complaint is really that if you do that, the objects will bounce off each other before you apply the joint. Box2D does not yet support the level of filtering you describe.
Work arounds include:
  • Manually resetting the velocity of the two bodies after the collision. This works in most circumstances.
  • Creating a copy of the bodies, but making them sensors, and keep the two copies on top of each other. You filter the solid collisions, but allow the sensor ones to reach the contact listener. This is effective, but annoying to implement, and possibly more demanding on resources.
Thanks for the tips Boris. I suspect the sensors are the most appropriate solution for this situation. I'm guessing the workflow would involve me pairing a sensor with each physical body, setting them to ignore their partners, and to react to the others. This would double the number of objects being simulated, so perhaps i will look for another way, or instead redesign my game. Thanks again!
Box2D typically bottlenecks on the collision resolution, or so I'm told. So adding extra sensors will have a small effect on performance.

Original thread: https://box2d.org/forum/viewtopic.php?t=1746