Physics: body categories and masks

I’ve not found any documentation about the categories and masks properties of physics bodies. I’ve found the example in the physics playground example but I’m not sure how to apply the properties to my own projects.

How do the categories and masks for two bodies relate when doing collision detection?

Do all bodies get default values for these properties? If so, what?

Here’s how it works. Each body has 16 categories and 16 masks, by default categories = {0} and mask = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}. Two bodies will collide if

bodyA.mask contains any bodyB.categories and bodyB.mask contains any bodyA.categories

So by default all bodies will collide with each other. These properties also apply to sensors.
Here’s an example, players don’t collide with each other, monsters don’t collide with each other, but players and monsters do collide:


player.categories = {PLAYER}
monster.categories = {MONSTER}
player.mask = {MONSTER}
monster.mask = {PLAYER}

Just on a side note, I’ll make a section just for collision filtering in the physics documentation when I get the chance