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

Collision Example

Topics: User Forum
Jun 15, 2008 at 4:29 AM

For the life of me I can't figure out how to handle collisions in the latest release. I've got two objects (A and B). I need to know when object A specifically hits object B so I can do stuff to B.

I tried if(B.geom.collide(A.geom)) but that throws up an exception in Geom.cs complaining about worldVertices must be non-negative.

Can anyone give me a quick rundown and example of how to handle collisions?

I also need to have object A pass through another object but still trigger a collision. But I'd like to solve the main problem first.

Jun 15, 2008 at 8:57 AM
Here is an example:

    geom.Collision += new Geom.CollisionEventHandler(collisionTest);

public bool collisionTest(Geom geometry1, Geom geometry2, ContactList contactList)
    //return true to make the collision happen,
    //return false to let the physics engine ignore the collision

    return true;

Note that geometry1 and geometry2 are the two colliding geoms, and you can test if they are of certain object types, for example.

Hope that helps.
Jun 15, 2008 at 9:21 PM

It helped a lot! Thank you.