Need help detecting the collision of an object's center

Topics: User Forum
Feb 21, 2013 at 6:30 PM
Edited Feb 21, 2013 at 6:33 PM
Hello,

I have been trying to use farseers collision detection to detect the center of the objects body colliding with another object.

I wrote something like this but it doesnt work unless the center is exactly the same number.
            if (fixtureA.Body.WorldCenter.Equals(fixtureB.Body.Position)
                && fixtureB.Body.UserData == "AI_Waypoint_Zone"
                 && fixtureB.Body.BodyId < 3)
            {

                CarManager.Car_List[fixtureA.Body.BodyId].Active = false;
            }
i dont know if there is an easyer way of doing something like this.. please let me know!!! lol

Thank you for the help.
Feb 21, 2013 at 6:32 PM
Edited Feb 21, 2013 at 6:34 PM
going crazy lol.....
Feb 22, 2013 at 9:43 AM
Edited Feb 22, 2013 at 9:44 AM
Hi.

I assume that you are putting your code into the collision call back?

As you correctly deduce, your method is not great for detecting the collision with an object, as you will rarely have your fixture centre points pass over each other precisely!

I think more generally you need to reassess how you are approaching your problem.

It looks to me like you want to detect the collision of a body with a waypoint? Sounds like one body is a sensor? or you are return false to the collision call back, as clearly whatever it is you are colliding you do not want them to bounce off each other (otherwise their middles would never touch!)

You have a couple of options, depending on your exact requirements, but probably the most obvious:
If you want to detect a body passing close to a certain point, you can create a Senor body and affix a small circle to it, so rather than trying to check for collisions at a point, you are checking for collisions within a relatively small circle (much more likely to collide). This assumes you are happy with ANY part of body A, passing through the centre point of B's fixture triggering the collision.

If you are checking centre point versus centre point, you could add a small circle to A at the centre and obviously also keep the small circle at B, you could even put them in their own collision categories and wait for them to collide.

Anyway, hope that helps a bit. I think the key message is CHECK/COLLIDE AREAS/SHAPES NOT EXACT POINTS :)