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

Checking if a body is colliding with another body.

May 26, 2008 at 1:40 AM
Is it possible to check if a body is colliding with any other rigid body? Even a way to check against one will help. Because I can't seem to find anything about this anywhere in the library.
Oct 2, 2009 at 8:06 PM
Edited Oct 2, 2009 at 8:09 PM

You'll need a list with all Geometry's.
Then you just iterate through them all, and check if they're colliding.
myself is the Geometry you want to check is colliding with anything.
GeometryList is the List<Geometry> with all existing Geometry's.


public bool IsColliding(Geom geometry)
    bool IsColliding = false;
    foreach(Geom g in GeometryList)
        if (g != myself)
        if (myself.Collide(g))
            IsColliding = true;
    return IsColliding;





Oct 2, 2009 at 8:10 PM

MulleDK19's solution will work - however, it will add a lot of extra overhead because you iterate all geometries in the engine. Another way is to use the OnCollision event. The OnCollision event (delegate actually) is fired whenever a geometry (One you define) collides with another geometry.

It is described in the manual how you use the OnCollision event.