Box2D Group Indices

2017-12-20 02:38:28 +0000, 9 months and 4 weeks ago

What are Group Indices?

The group index flag can be used to override the category or mask of a fixture. As the name implies it can be used to group certain fixtures together to describe if they should or should not collide, a good example would be Friendly Fire, friendly players don’t get hit by friendly bullets, vice versa.

A group index is an integer ranging from -32768 to 32767.

Fixture:setGroupIndex( index )

How they work

What we’re really interested in are the last two points.
I’ll give an example, say we have two rectangles, A and B.


They both have the same index, 1, which is a positive number, therefore A and B will collide.


Although A and B have the same absolute value, 1, they are not the same number, thus they fit into the point of non-zero but different.


Finally, both fixtures have the same index and are negative, therefore there is no collision between the fixtures.




there's some rate-limiting going on with my comment provider atm, so i'd reccommend copying your message incase it gets blocked and retrying