Ignoring body collisions in Box2d (iphone)

I have 3 types of bodies. they

1) MouseJointBody (it moves only with mouseJoint)

2) 2 MovingBodys (it is constantly moving in the world)

3) StaticBody (fixed in a constant position)

I need to collide between these bodies:

1) MouseJointBody with MovingBodys and StaticBody and world bounderies

2) StaticBody only with MouseJointBody

3) MovingBodys only with MouseJointBody and world bounderies

4) MovingBodys collide with each other

but no need to deal with StaticBody and MovingBody. I set the filter data for these bodies as shown below:

StaticBody:

fixDef.filter.categoryBits=0x0004; fixDef.filter.maskBits= 0x0002; 

MovingBodys:

 fixDef.filter.categoryBits=0x0004; fixDef.filter.maskBits= 0x0002; 

MouseJointBody:

 fixDef.filter.categoryBits=0x0002; fixDef.filter.maskBits= 0x0004; 

Everything works fine, but my MovingBodys don't collide with eachother, and MouseJointBody and MovingBody don't collide with the world field. these two are leaving the world. please tell me the solution for this.

+4
source share
2 answers

In Farseer, which is the proyect base in Box2D, there is a CollisionCategory, but in Box2D to solve different

please see the following discussion

the idea is to designate this type of body each, and that bodies can only collide.

in the discussion of the matched case, A hits B, C hits D, but A misses A

0
source

I think when you use filters, you need to apply filters to the walls. And install maskBits from all.

MovingBodys example:

 fixDef.filter.categoryBits=0x0004; fixDef.filter.maskBits= 0x0002 | 0x0006; 

(0x0006 - bit wall category)

0
source

All Articles