Category bits vs Mask bits

I’m confused about how to write complex collision filters. I feel like I understand the red balloon vs blue balloon sample, but when adding more objects it does not seem to follow the pattern.

From the sample:

local redCollisionFilter = { categoryBits = 2, maskBits = 3 }   
-- red collides with (2 & 1) only  
   
local blueCollisionFilter = { categoryBits = 4, maskBits = 5 }   
-- blue collides with (4 & 1) only  

I assumed that if I added a third filter “green” with category of 6 and mask of 7 that it would collide with 6 and 1 only. However this does not seems to be the case.

How does the formula work for adding more filters?

My goal is two have 4 objects that each shoot their own set of bullets. The objects cannot crash into each other or their own bullets, but they can crash into each others’ bullets, so how do I go about writing that?
[import]uid: 10903 topic_id: 9428 reply_id: 309428[/import]

Category bits can only be power of 2… so valid values for category bits are 1, 2, 4, 8, 16 and so on.

6 is not acceptable value for category bit :slight_smile: [import]uid: 48521 topic_id: 9428 reply_id: 34519[/import]

How do mask bits work then? Is it just the mask bit number minus the category bit number? [import]uid: 10903 topic_id: 9428 reply_id: 34521[/import]

If you’re confused, have a look at this excellent post from IgnisDesign. [import]uid: 51516 topic_id: 9428 reply_id: 34523[/import]

That is very helpful thank you. [import]uid: 10903 topic_id: 9428 reply_id: 34642[/import]