Collision Categories/Groups

Topics: Developer Forum, User Forum
Feb 7, 2009 at 7:42 AM
I'm trying to use collision categories in my game (to control overall collisions between objects) but they are not working right now... Perhaps someone could enlighten me as to the exact way these are used? i've looked at the collision categories sample(s) but they didnt help. At one time (long ago) they worked, but i can't figure out why. Help!
PS. what is the difference between collision categories and groups? one of them (i cant remember which, the one that uses numbers instead of bitmasks) seems redundant and useless.
Feb 7, 2009 at 8:56 PM
CollisionGroup is the one that uses numbers. It's easy to use and straight forward.
CollisionCategories on the other hand are a little more tricky.

You have CollisionCategories and CollidesWith. If you have 2 types of objects: red and blue. You would like the following collision behavior:

1. You want the red ones to collide with themselves and the blue.
2. You want the blue ones to collide with red, but not with themselves.

You do it like this:

redBalls.CollisionCategories = CollisionCategory.Cat1;
redBalls.CollidesWith = (CollisionCategory.Cat1 | CollisionCategory.Cat2);

blueBalls.CollisionCategories = CollisionCategory.Cat2;
blueBalls.CollidesWith = CollisionCategory.Cat1;

You can even extend it with some green balls. They should collide with everything but the red balls:

blueBalls.CollisionCategories = CollisionCategory.Cat3;
blueBalls.CollidesWith = CollisionCategory.All  & ~CollisionCategory.Cat1;

Just to clarify what the operators mean:
1.   |     This one means OR
2.   &   This one means AND
3.   ~|   This one means NOT

You can even make an XOR (^)

Oh, and this is also documented in the manual. Might put this in if it's easier to understand.
Feb 8, 2009 at 4:14 AM
I think i understand the problem i'm having here. I was using the double bars (||) instead of the single bar and i suspect that breaks it. Might want to add that too (that you need to use those separate operators for bitwise ops, cause i dint get it and i think i read the document that describes that stuff)