Collision filter mask works ugly

Chaz
Posts: 44
Joined: Mon Jan 12, 2015 1:36 pm

Collision filter mask works ugly

Post by Chaz »

Hello. I guess I don't understand how to work with collision filtering.
For example, I have object with filter group = 10 and filter mask = 1, and then I cast a ray with filter group = 20, and it works good - ray ignores object.
But if I change filter mask of the object, for example, filter mask = 25 then it gives collision between ray and object.
Why it so? I just want to make collision only between objects with filter group 10 and 20, not between 10 and 25.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Collision filter mask works ugly

Post by Erwin Coumans »

Collision masks and filters work bit-wise.

Good luck!
Chaz
Posts: 44
Joined: Mon Jan 12, 2015 1:36 pm

Re: Collision filter mask works ugly

Post by Chaz »

Erwin Coumans wrote:Collision masks and filters work bit-wise.

Good luck!
Do you mean that object with collision flag 10 and mask 25 will be collide with all objects which has collision flag less than 25 ?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Collision filter mask works ugly

Post by drleviathan »

He means that if you write 10 in 16-bit binary you get: 0000 0000 0000 1010. What matters is that two bits are set: the second bit from right, which represents the value 2, and the fourth bit from right, which represents the value 8 -- add them together and you get 10. Similarly 25 would look like: 0000 0000 0001 1001 = 1 + 8 + 16. Each bit of the collision filter represents a collision group that can be enabled or disabled -- you only have 16 of them because they are stored in a 16-bit value.

Collision filter 10 is in two groups (2 + 8) and collides with something with collision filter 25 (1 + 8 + 16) because they are both in group 8. Meanwhile collision filter 20 (4 + 16) shares no groups with 10.
Chaz
Posts: 44
Joined: Mon Jan 12, 2015 1:36 pm

Re: Collision filter mask works ugly

Post by Chaz »

drleviathan wrote:He means that if you write 10 in 16-bit binary you get: 0000 0000 0000 1010. What matters is that two bits are set: the second bit from right, which represents the value 2, and the fourth bit from right, which represents the value 8 -- add them together and you get 10. Similarly 25 would look like: 0000 0000 0001 1001 = 1 + 8 + 16. Each bit of the collision filter represents a collision group that can be enabled or disabled -- you only have 16 of them because they are stored in a 16-bit value.

Collision filter 10 is in two groups (2 + 8) and collides with something with collision filter 25 (1 + 8 + 16) because they are both in group 8. Meanwhile collision filter 20 (4 + 16) shares no groups with 10.
I guess I got it. That's why in manual is written "This means you can have up to 15 different groups, and 15 different masks."
So I just have to assign to each object collision filter which is power of 2.
Thanks!
p.s. sry for my bad English