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

Collision detection question.

Topics: User Forum
Jan 23, 2009 at 2:38 PM
I have a quick question. Is there anyway to query the current number of collisions for a given object? I currently have an object that I want user actions to process for only if the object is currently colliding with something. Is there a bool value or a collision count saved for each collision object??

Thank you.
Jan 23, 2009 at 6:07 PM
There is no collision count in Farseer Phyiscs, but we have all the tools you need to make such a thing.

I can see 3 ways, depending on how accurate you want the collision detection:

1. Use the OnCollision event that fires when a collision occurs. You can subscribe to the event of a specific object and count the times it collides with other objects. You might want to check the velocity on impact or use it in combination with the OnSeperation event to detect unique collisions.

2. Use the Geom.Collide() method to check collision against one or more geometries. This method returns a boolean value. (true = collision)

3. Warning: Is not as precise as the other 2 because it only uses AABBs (Axis Aligned Bounding Box). Every broadphase collider has also a OnCollision event that fires when 2 AABBs collide.