This project has moved and is read-only. For the latest updates, please go here.

Turning Chain Collision off

Feb 8, 2011 at 8:22 PM

I'm creating a chain, per the Testbed example:


	    //Chain start / end
            Path path = new Path();
            path.Add(new Vector2(0, 20));
            path.Add(new Vector2(30, 20));

            //A single chainlink
            PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(0.125f, 0.6f));

            //Use PathFactory to create all the chainlinks based on the chainlink created before.
            List<Body> chainLinks = PathManager.EvenlyDistibuteShapesAlongPath(World, path, shape, BodyType.Dynamic, 20, 1);

            //Fix the first chainlink to the world
            FixedRevoluteJoint fixedJoint = new FixedRevoluteJoint(chainLinks[0], Vector2.Zero, chainLinks[0].Position);

            //Attach all the chainlinks together with a revolute joint
            PathManager.AttachBodiesWithRevoluteJoint(World, chainLinks, new Vector2(0, -0.6f), new Vector2(0, 0.6f),
                                                      false, false);

The resulting List of bodies collide with my other game fixtures by default (even fixtures assigned to never collide with anything), and I want them not to.

What's the best way of turning off Body collision? At the moment, I can't find a way to do it, and PathManager.EvenlyDistribute requires a List<Body> rather than List<Fixture>

Any pointers would be awesome :)

Feb 8, 2011 at 10:57 PM

You can change the collision properties on the fixtures by iterating Body.FixtureList.

You have several ways of filtering collisions, CollisionGroups and CollisionCategories are the most flexible and common ones.

Feb 9, 2011 at 8:22 AM

Works a charm, thank you. Could have sworn I'd tried that ¬¬ 



Code, in case it helps others searching:


foreach (Body b in chainLinks)
    foreach (Fixture f in b.FixtureList)
            f.CollisionCategories = CollisionCategory.Cat2;
            f.CollidesWith = CollisionCategory.Cat2;