I'm using cocos2d js 3.8 with chipmunk physics, I'm trying to filter collision but it's not work, i have set
shape.categoryBits =1;shape.maskBits =2;
for player and shape.categoryBits =3;shape.maskBits =4;
for enemies
but they're still colliding. Did i do something wrong?
0
votes
1 Answers
0
votes
I'm not sure about js, but I think collision detection the same as in Cocos2d-x.
So, try set shape.categoryBits = 1; shape.maskBits = 1;
for player and shape.categoryBits = 2; shape.maskBits = 2;
for enemies. In this case, the hero should not collide the enemies, but the enemies should collide each other.
The basic idea is the condition for the non-colliding objects:
(shapeA.categoryBits & shapeB.maskBits == 0) || (shapeB.categoryBits & shapeA.maskBits == 0)
But now you have (0001 & 0100 == 0) || (0011 & 0010 == 0)
is false because 0011 & 0010 = 0010
, and condition is not met.