Explanation use of property `group`
Can you provide more info on how the collision filtering works with the group property, is more for our use or is it used internally?
for your use. will explain shortly. for now refer to demo stress test @gregmax17
I read through the code and will give an explanation to the best of my understanding.
It appears to only be used by the canInteract function. Is like a double bitmask where the top 16 bits are the groups that it can interact with and the bottom 16 are the groups it belongs to. Bodies with the same group number will always be able to interact.
The predefined groups use less than the first 8 bits so the upper 8 bits out of the lower 16 should probably be used for custom groups, 0b00000001 << 16 to 0b10000000 << 16.
- Predefined groups:
-
0b00000000_00000000_00000000_00111111
-
- Candidates for custom groups:
-
0b00000000_00000000_11111111_11000000
-
- "canInteract"-flags (corresponding to the
group_value << 16):-
0b11111111_11111111_00000000_00000000
-
Example:
- Body 1
-
0b00000000_00000000_00000001_00000000
-
- Body 2
-
0b11111111_11111111_00000011_00000000
-
- Body 3
-
0b00000010_00000000_00000100_00000000
-
Body 1 has the first custom group but cannot interact with any other groups except itself because the first 16 bits are all zeros, only bodies with an identical value can interact with it. Body 2 has the first and second group and can interact with all other custom groups , but only if that body also can interact with is custom group. Body 3 has the third group but can interact with the second group. This means that Body 2 and Body 3 can interact with each other but no other body can interact with Body 1 because it doesn't allow interactions with any other custom group.
@Prozi If you would like I could make a PR with this documentation added to the group property and the canInteract function with a simple version of this explanation, mainly this part:
- Predefined groups:
0b00000000_00000000_00000000_00111111- Candidates for custom groups:
0b00000000_00000000_11111111_11000000- "canInteract"-flags (corresponding to the
group_value << 16):
0b11111111_11111111_00000000_00000000
The concept of group comes from Box2D's filtering. Here are two links, hope they're helpful.
Box2D Doc (Box2D > Simulation > Shapes > Filtering) Box2D Tutorial: Collision filtering
@Prozi If you would like I could make a PR with this documentation added to the
groupproperty and thecanInteractfunction with a simple version of this explanation, mainly this part:
Predefined groups:
0b00000000_00000000_00000000_00111111Candidates for custom groups:
0b00000000_00000000_11111111_11000000"canInteract"-flags (corresponding to the
group_value << 16):
0b11111111_11111111_00000000_00000000
I always love contributions and merge requests so please do
The concept of
groupcomes from Box2D's filtering. Here are two links, hope they're helpful.Box2D Doc (Box2D > Simulation > Shapes > Filtering) Box2D Tutorial: Collision filtering
Thank you for the links
@RedPhoenixQ if you could someway include both of those as also references for docs please do
I think if I recall correctly @noih is the author of those group functions in detect-collisions
Thank you both for using our great library!
@Prozi If you would like I could make a PR with this documentation added to the
groupproperty and thecanInteractfunction with a simple version of this explanation, mainly this part:
Predefined groups:
0b00000000_00000000_00000000_00111111Candidates for custom groups:
0b00000000_00000000_11111111_11000000"canInteract"-flags (corresponding to the
group_value << 16):
0b11111111_11111111_00000000_00000000
@RedPhoenixQ any update on that PR please?
I'm anxious and excited for collision filtering like this. It would be really helpful!
@Prozi sorry for the long pause without response. I've made a PR now
thank you very much @RedPhoenixQ
your mr was really good
I ran all the precommit scripts on it and published it here (and on npm)
https://github.com/Prozi/detect-collisions/releases/tag/v9.17.0
@gregmax17 can we close this now if the link above is explaining ok?
Thank you!
yay! @gregmax17 closing as resolved