Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to make a game that uses Farseer physics engine as its main collision detection engine. I have a 2d circle body object that has a matching fixture (I used the CreatCircle method. I did not create the fixtures and bodies separate). When IsSensor is set to false, objects collide with this circle and bounce off. My goal was to have events triggered when other physics enabled bodies move through this field and just use the engine to detect the collisions (or rather intersections) so I set it to IsSensor = true, and now all the other bodies pass right through but I do not get collision events. The be specific, sometimes I do get events but not continuously as I would expect. My intention was to have this collision code fired each time the world re evaluated collisions.

Does anyone know a way to do this. My googling has led me nowhere and I'll be fudging with the limited farseer documentation I can find this weekend to try and get this right.

Thanks ahead of time.

share|improve this question
up vote 0 down vote accepted

Get the Body.ContactList which is populated by all contact resulting from BB collisions. If you want contacts that actually have fixtures touching check to see if Contact.IsTouching() is true.

Edit: There are performance issues with this approach so I suggest setting a flag when the sensor collision event fires and setting the flag to false when none of the items in the ContactList are touching. Only iterate though the contact while this flag it set to true. This would prevent you from iterating every every time a BB intersects with your sensor.

share|improve this answer
So this would be a home rolled collision check, probably in the update method of the game component and not an event I can register a delegate for? – Flostation Feb 16 '12 at 21:14
Yes. However, you can use the collision event to kick of the collision checking and stopping as soon as no objects are touching reducing the workload if you are worried about performance issues. See my edit. – ClassicThunder Feb 16 '12 at 21:28
I like this approach but I'm running into a problem with the initial OnCollision and the following OnSeperation events. The don't get fired right away when the initial contact with the fixtures is made and the separation event is never fired. It seems to almost randomly choose when to flag collision. Would timing with a sensor type body be an issue when looking for collisions? – Flostation Feb 16 '12 at 21:37
I believe with sensors you are supposed to use BeginContact and EndContact in the ContactListener. Don't have the API in front of my so I may be remembering incorrectly. – ClassicThunder Feb 16 '12 at 21:43
This pretty much worked. I'm still having issues with the timing of the BeginContact and EndContact events. They sometimes don't fire till in the middle of my sensor circle, but at least they are firing. I can post some example code if someone is having this same problem. I had to fumble around the codebase of farseer a little to figure out what delegates to add my methods to. Its not really spelled out in any documentation. Coming from using Java all day every day at work, this really makes me longingly pine for Javadocs... Sigh. Some day. Some where. – Flostation Feb 20 '12 at 20:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.