it will collide with any other physics body with a collisionBitmask of xxxxxxx1
Think of the contactTestBitmap as defining the type of object, and the collisionBitmask as defining which object types I want to collide with. a ‘1’ in the same position in the bit mask means Yes - a collision happens.
If you go back to the thread I mentioned and read my post - where I say ‘CategoryBitMask’ read ‘ContactTestBitMask’
Hi @Maxxx
I did follow your thread(must say it is amazing! BTW) .
I thought the same too. But it is not happening for some reason. I have 4 objects. Walls,Player,Bot and Bullet. I have set given them following CategoryBitmask
int playerCategoryMask = 0x1; // 0001
int worldCategoryMask = 0x2; //0010
int botCategoryMask = 0x4;//0100
int bulletCategoryMask = 0x8; //1000
Now say If I want bullet to give contactBody on touching walls then bullet's ContactBitMask should be 2(worldCategoryMask)
So I created method in Bullet
now this contactlistener should work if bullet and walls touch but it doesn’t. In fact other collision type(between player and bot) is picked up even though I have created eventListener Player Class as well.
You shouldn’t use ‘+’ you should use ‘&’ (not saying this is whats causing the problem as I haven’t looked closely, but this only works if you happen to have single bit bitmasks)
e.g. 3 + 2 = 5
011 + 010 = 101 … not what you want
011 &010 = 010 … which is what you want…
If I were you, to find out where the bug is, I’d hard-code the mask values - if it works, then you know that’s where the problem lies (i.e. the wrong values).
Hi @Maxxx ,
Thanks for responding. Even though you were right that rather than ‘+’ I should use ‘|’ but in this particular case it wont matter. Thing is I have found out when it catches event and when it doesn’t.
So if let us say if I have to catch ContactBody between bodyA and bodyB then I would have to setContactTestBitmask separately for both of them, then and only then it onContactBegin is fired.
I am not sure but I guess this is bug
PS: all EventListenerPhysicsContact handlers are still called ,is this normal?