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

Get a list of bodies in touch when the bodies at rest

Topics: Developer Forum
Mar 9, 2013 at 9:51 AM
Edited Mar 9, 2013 at 10:38 AM
I have a scenario in my 2D game (xna+farseer), here i am trying to get list of bodies in contact when all the bodies at rest. i can get list of bodies with OnCollision event, but this will not be at bodies rest.
Please let me know how to identify list bodies in contact when the bodies are in rest.
Mar 12, 2013 at 7:02 PM
I think the ContactList property on Body is what you are looking for. You can iterate over the ContactList to see what other bodies are in contact at any time.

Hope that helps,
Mar 13, 2013 at 3:17 AM
I do believe that we can use ContactList, but not sure which property or method to drilldown/iterate, there are some methods (Contacts, Next, Other and Prev), tried extracting these but no luck, If you could please reply with an example or a link would help.
Mar 13, 2013 at 4:08 AM
I think this should work:
 private List<Body> GetBodiesInContactWithBody(Body body)
            var bodiesInContact = new List<Body>();
            var c = body.ContactList;
            while (c != null && c.Next != null)
                if (c.Contact.IsTouching())
                     // if the above doesn't work ( haven't tried this code) try the below:
                     // if (c.Contact.FixtureA.Body == body)
                     //     bodiesInContact.Add(c.Contact.FixtureB.Body);// FixtureA is the body we're getting contacts for, so add fixtureb
                     // else 
                     //     bodiesInContact.Add(c.Contact.FixtureA.Body);
                c = c.Next;
            return bodiesInContact;
Hopefully that will work for you.

Mar 13, 2013 at 1:21 PM
Great !! Thanks much :)