Setting Up Collisions

Topics: Developer Forum, Project Management Forum, User Forum
May 8, 2008 at 7:42 PM
Are there any tutorials available on setting up collisions using the latest release. There seems to be some content which suggests that you need to create a method delegate for the CollisionHandler on the Geom but it appears as if this simply called Collision now.

I have attempted to create a handler here using the line;

marbleGeometry1.Collision += new Geom.CollisionEventHandler(CollisionHandler);

and defining the method;

protected bool CollisionHandler( Geom g1, Geom g2, ContactList list ) {

return true;
}

but this method is never being called!

Just wondering if someone can explain what needs to be added.

Thanks!
May 8, 2008 at 9:57 PM
Edited May 8, 2008 at 10:05 PM
The Collision event defined in the Geom object should probably be defined as:

public event CollisionEventHandler Collision = delegate { return true; };

instead of:

public CollisionEventHandler Collision;

The calls to it would have to change as well, outside classes would need to call another method on Geom such as:

internal void RaiseCollision(Geom g1, Geom g2, ContactList list)
{
this.Collision(g1, g2, list);
}

Then other methods such as the ones in the Arbitrator class would call geometry1.RaiseCollision(geometry1, geometry2, contactList);

I don't know if that will solve your problem but that is the way to define and subscribe to events in C#.

I haven't tried this or modified the code but this is how I would do it.