[Box2D] Detect collision between two b2Bodies

I created two b2Bodies with b2BodyFixtureDef:

//Def1
BodyAFixtureDef.filter.categoryBits = 0x0001;
BodyAFixtureDef.filter.maskBits = 0x0001;
//Def2
BodyBFixtureDef.filter.categoryBits = 0x0002;
BodyBFixtureDef.filter.maskBits = 0x0002;

then create two bodies with them:

How to Detect collision between two b2Bodies, that has a different categoryBits and maskBits index to other?
many thanks!

They won’t collide because of the bit masks you’ve set.

the mask bits tell the engine what categories to collide with

As 0x0001 AND 0x0002 == 0x0000 there will be no collision

Set the mask to 0x0003 on them to make them collide

@Maxxx thanks for rep!
I want them to get through to each other, but able to detect when bodyA comes into bodyB’s position. how could I do that?
sorry my english so bad

i think what you’re looking for is sensor fixtures … Here take a read.

Joseph beat me to it - and he’s right. A sensor detects collisions but doesn’t act on them - so setting the IsSensor property to true, and the bitmasks so that they will collide, will give you what you’re after.

Its what I’m looking for. thanks! :slight_smile: