Collision Filter confusion

Hello,

I have a set of boundaries around my game that i want enemies to be able to pass but not the player, however i still need the enemies to collide with the player. How can i make this work?

Thanks
Read the manual... search for contact filtering...
haha "rtfm" alright 😛

Just for the sake of supplying some more info, i did read up on it and at the moment:

Walls: categorybit = 2
Enemy: maskbit = 4
Player: maskbit = 6;

Enemy doesn't collide with the wall and passes through
Player can't pass the wall but doesn't collide with the player

What i need to get working is enemies only colliding with the player; by passing walls hat the player can't.
You need to set the category bit on the enemies, too.

As an example, if you have players in category 1, walls in category 2, and enemies in category 4, and you want players to collide with enemies, enemies to collide with players, and everything to collide with walls, you do something like the following:

player.category = 1
wall.category = 2
enemy.category = 4
enemy.mask = 3
player.mask = 6

If you wanted enemies to not collide with walls (all walls in this case) you'd set the mask to 1 instead.

Generally you put things into one bit category and use masks to determine all the categories that something collides with.
For the sake of visualization, you can do this.
(a bit psuedo cody)
Code:

enum CollideBits 
{ cbNone = 0, cbWall = 1, cbPlayer = 2, cbEnemy = 4, cbBullet = 8 /*16,32,64...*/ };

player.filter.categoryBits = cbPlayer; // Player is a player
player.filter.maskBits = cbWall | cbEnemy | cbBullet; // should collide with wall, enemy & bullet.

enemy.filter.categoryBits = cbEnemy;
enemy.filter.maskBits = cbPlayer | cbBullet;

wall.filter.categoryBits = cbWall;
wall.filter.maskBits = cbNone; // Player and enemy mask this for collision anyway, so will still collide.
 

Original thread: https://box2d.org/forum/viewtopic.php?t=6719