how to set up collision groups?

I’m trying to set up a system for detecting different types of collisions in a game. There are:

-bullets that the character shoots at enemies
-bullets that the enemies shoot at the character
-level boundaries
-collisions for world mouse location
-various inanimate objects that are impassable
-special collisions, like treasure chests and other objects the main character interacts with.

How do I seperate all these different types of collisions? Is there some sort of standard implementation?

Thanks for any answers!

You can use bitmasks to indicate different kinds of objects that have different kinds of collisions.

If you are using the Panda collision system, there is a pattern-matching event system that is quite extensive. You can flag collision events based on object name or tags.

You use the collision masks for broad sweeps, and then refine the actual collision behavior with events. For example, I want my enemies to have a special behavior when colliding with terrain, versus colliding with static geometry that is a part of the world. If both use the same collision bit mask, so how do I differentiate between the two?

One way could be perform a traversal and then loop through the collision queue, checking to see if these objects are of certain types and act upon that type. But this is inefficient to do in Python code. You also have to be careful concerning cases where you want to register just the first collision but not any subsequent ones.

Instead, I filter based on the event that is triggered. That way, I only process events of the type I care about. An example:

self.collisionNode.addInPattern ('%(collisionCategory)ft-into-%(collisionCategory)it')

self.accept ('enemy-into-ground', self.groundCollision)
self.accept ('enemy-into-building', self.buildingCollision)

The nice thing about the event system is you can have it watch for one-time collisions or repeated collisions. (using addAgainPattern)

Update: To be clear, I am using tags associated with my collision nodes. So, on my enemy object collision node, I have enemy.setTag (‘collisionCategory’, ‘enemy’) and on my ground collision node I have ground.setTag (‘collisionCategory’, ‘ground’) You could just as easily filter based on node name.