does anyone know whether bodies only collide when (body1.categoryBits & body2.maskBits) && (body1.maskBits & body2.categoryBits) ? or do they already collide when (body1.categoryBits & body2.maskBits) || (body1.maskBits & body2.categoryBits) ?
相关问题
- Why shouldn't I use pixels as unit with Box2D?
- Is there a functional difference between “2.00” an
- Pygame - Collision detection with two CIRCLES
- Fast moving bodies miss the collision sometimes in
- How to set centers of shapes/fixtures/bodies in Bo
相关文章
- Tag multiple branches in git?
- Position resizable circles near each other
- Solving a cubic to find nearest point on a curve t
- Strange “stutter” in box2D on different android de
- AndEngine Sprite/Box2D Body removal crashes my pro
- Libgdx | Scene2d | Set background color of table?
- Libgdx game crashes on Android
- Getting the Protrusion and Collision Data From Jqu
From the Box2D manual:
I have used walls and many players (our Player and enemies). My player and enemies collides with walls but don't collide with each other. I have done like this and it worked. You have to set the groupIndex to negative value for the objects not to collide with each other. Define the fixtures like this.
and apply to your bodies.
Looking at the source of Box2d, it shows that if the fixtures belong to different groups (or the groups are 0) then the catgory and masks are compared as follows:
So it looks like fixture only collide if the collision is allowed by both fixtures' masks. (IE: AND logic)
If anyone is still looking for more explanations, I made a detailed tutorial here :
http://aurelienribon.wordpress.com/2011/07/01/box2d-tutorial-collision-filtering/
This is the way I've understood how maskBits and categoryBits work. Let's say you have 3 objects : objectA, objectB and objectC.
Define for each object a category :
objectA.categoryBits = 0x0002;
objectB.categoryBits = 0x0004;
objectC.categoryBits = 0x0008;
Then, set the maskBits, which define the collisions rules for each categoryBits :
-> objectA collide with everyone (0xFFFF) and (&) not(~) objectB (0x0004)
objectA.maskBits = 0xFFFF & ~0x0004;
-> objectB collide with objectA (0x0002) or (|) objectC (0x0008) but no one else
objectB.maskBits = 0x0002 | 0x0008;
-> objectC collide with objectA (0x0002) but no one else
objectC.maskBits = 0x0002;
I don't know if this is correct, but it worked for me.
HTH