This project has moved. For the latest updates, please go here.

Runtime CollisionGroups

Topics: Developer Forum
May 17, 2011 at 1:53 PM
Edited May 17, 2011 at 1:53 PM


 I'm trying to add a new fixture to a collision group, but it seems to not be working. I have a few fixtures, for which I set their collision group to '1' (during initialization) and they don't collide with each other. However, I'd like to create certain fixtures dynamically in game, but even if I set their collision group to '1', they still collide with everything. An example fixture:

Fixture fixObstacle = FixtureFactory.CreatePolygon(world, first, density, position);                                            
fixObstacle.Body.Rotation = propDef.Rotation;
fixObstacle.Body.LinearVelocity = propDef.LinearVelocity ;
fixObstacle.Body.AngularVelocity = propDef.AngularVelocity;
fixObstacle.Body.BodyType = BodyType.Dynamic;
fixObstacle.Body.Position = propDef.Position;
fixObstacle.CollisionFilter.CollisionGroup = 1;


Do I have to set something else in order to add this fixture to collision group '1' so that it doesn't collide with any other group '1' bodies?


Jun 8, 2011 at 4:32 PM

Sorry for the late reply.

For disabling collisions with collisiongroups, you have to set the group to a negative number.

Collisiongroups with positive number means they always collide.

Collisiongroups with negative number means they never collide.

More details, you can look at the Box2D manual, in the section 6.2: