CollisionCategories mayhem

Topics: Developer Forum, User Forum
Sep 24, 2009 at 9:43 AM

Hi, I have a problem with CollisionCategories, iI've checked this post, also the manual but I can't make this work.

I have two geoms:

geom1.CollisionCategory = Cat1 & Cat2;

geom2.CollisionCategory = Cat3;

What I want to do is to make geom2 to collide only with geom1, nothing else, so I do:

geom2.CollidesWith = CollisionCategory.None & Cat2;

But that doesn't work, it still collides with everything. So I tried:

geom2.CollisionCategory = CollisionCategory.None & Cat3;

But now it doesn't collide with anything, not even geom1.

Help please!

Sep 24, 2009 at 9:52 AM

Well by the looks of it you have told geom2 to collide with nothing... Why did you do that if you want it to collide with geom 1?
Just make geom2.CollidesWith = Cat1 or Cat2;

Sep 24, 2009 at 10:40 AM

I thought that telling not to collide with anything and with Cat3, would make the geom collide only with Cat3.

If I do what you told me, then geom2 collides only with the geoms that have this:

geom3.CollisionCategory = Cat1;

But not with:

geom1.CollisionCategory = Cat1 & Cat2;

 

Sep 24, 2009 at 10:49 AM

Well i could be wrong but i thought that by default a geom collides with only what you set it to. So telling it to just collide with cat3 should only make it collide with cat3 and nothing else.
If this was not true telling something to collide with cat3 would be pointless because it would already collide wih everything in the world.

Heres the little sheet i have been using in my testing game program thing to work out what collides with what...

"Name"  "CollisionCategory" "CollidesWith"

Player is 2 - with 1, 3, 4
Rope is 10 - with 1, 3, 4
Board is 3 - with 10, 2
Floor is ALL - with ALL
PhysicsBox is 3 - with 10, 2
Cannon is 1 - with 10, 2
CannonBall is 4 - with 10, 2, 3, 4

this made it all work fine for me.

Sep 24, 2009 at 11:09 AM

Thanks danthekilla, I will use your sheet as a reference :)

Sep 24, 2009 at 1:55 PM

Still having problems. It seems that the problem is when I try to assign more than one category to a geom.

Sep 24, 2009 at 6:46 PM

I see you're using AND (&), try using OR. ( | ).

Sep 24, 2009 at 8:09 PM

@Yota

Tried too, in different combinations (in th CollidesWith and CollisionCategories properties), I think I will continue with the try & error formula, but I would like to understand well how this works.

Sep 25, 2009 at 4:24 PM
Edited Sep 25, 2009 at 4:37 PM

Keep in mind that the 'CollidesWith' property of object A won't effect anything if object B is still set to collide with object A's category.

I haven't gotten to mess with Farseer in a while unfortunately, (full time sucks) but I'm pretty sure there should not be a single AND used in this.

None & Cat1 = None
None | Cat1 = Cat1
All & Cat1 = Cat1
All | Cat1 = All
Cat1 & Cat2 = None
Cat1 | Cat2 = both Cat1 and Cat2

Whether or not something collides depends on if one object's CollidesWith 'AND'ed with the others' CollisionCategory does not equal None. (Assuming CollisionGroups are the same.)

Ex:
(Cat1 | Cat2) & (Cat2) = Cat2 // Collides
(Cat1 | Cat2) & (Cat3) = None // No collision.
(Cat1 | Cat2) & (Cat1 | Cat3) = Cat1 // Collides

Sep 25, 2009 at 10:54 PM

Thanks Yota, I think everything is getting more clear now :)