Search code examples
collisionchipmunk

Controlling collision control in chipmunk


In chipmunk I have 3 types of objects: A, B and C. I need A and B not to collide. I also need B and C not to collide. On the other hand I need A and C to collide. For A and B not to collide I set their collisionGroup to be the same.If I set B and C the same collisioGroup this time A and C will have the same collisiongroup thus causing A and C not to collide. I've tried to set collisionMask/collisionCategories but that didn't help either. Any idea how to accomplish this?


Solution

  • Here's how I solved the problem.

     A.collisionGroup=@"beams"
     A.collisionCategory=@[@"beam"];
     A.collisionMask=@[@"box"];
    
     B.collisionGroup=@"beams"
     B.collisionMask=@[@"none"];
    
     C.collisionCategory=@[@"box"];
     C.collisionMask=@[@"beam"];
    

    To make it clear. I assign the same collision group to A and B so that they don't collide under any circumstances. This is because collision group overrides any behaviors defined with collisionMask and collisionCategory. Then I set up so that A collides only with C and C collides only with A. I do it by cross setting each other's collisionMask and CollisionCategory. One more and a very import thing to consider is if you don't want B also to collide with C you have to set collisionMask of B to something else otherwise B will collide with anything that is not in the same collision group. Phew, that's it.