0
votes

i have studied a lot about collision filtering using categories and masks and groups. they involve prevention of collision between related object while they do collide with opposite group. my case is totally different i have two groups and i want they should collide within the group so that bodies of different group can't collide with bodies of opposite group.

for example all blue balls can collide with each other and red ones with red ones. no blue ball can collide with red ball. any thoughts on this

1

1 Answers

0
votes

you can set group index negative to bodies which wont collide and similarly you can set group index positive to bodies which you want to collide.

Collision groups let you specify an integral group index. You can have all shapes with the same group index always collide (positive index) or never collide (negative index). Group indices are usually used for things that are somehow related, like the parts of a bicycle. In the following example, shape1 and shape2 always collide, but shape3 and shape4 never collide.

shape1Def.filter.groupIndex = 6;
shape2Def.filter.groupIndex = 6;
shape3Def.filter.groupIndex = -8;
shape4Def.filter.groupIndex = -8;