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

Using event handler OnCollision

Topics: User Forum
Nov 22, 2008 at 12:53 AM
Edited Nov 22, 2008 at 1:45 AM

I'm new to the Farseer Physics Engine, and am quickly learning how to use it. Due to the Engine being very user friendly, and great documentation, it has been easy to implement thus far. For my video game in the making, hosted at codeplex/saeculum, I'm using the CollisionEventHandler OnCollision for all of the objects on the screen, so they can deal damage to each other when they collide.

Here's a sample pseudo code:

for all balls in bullet ball pool which are checked out:
bullet.ball.Geom.OnCollision += OnCollision;
for all balls in enemy ball pool which are checked out:
enemy.ball.geom.oncollision += oncollision
for all balls in tower ball pool which are checked out:
tower.ball.geom.oncollision += oncollision

//all the geoms are treated the same in the physics engine?
//so all geoms have an ID for which pool its from and an ID for its position in the pool array
public bool OnCollision(geom1, geom2, contactlist)
logic for all three different combinations 9 possible

My confusion is to how the event fires, when it fires, where it fires, and if the oncollision should be a generic function which can handle all the different types bullet, enemy, tower, or if should have a different definition for the bullet, enemy, tower.

Or just a basic overview of how it works.

-Edit: I've realized that .Tag is good, but it's an Object, and have to box\unbox it. Boxing and unboxing high frequency code isn't nice on performance, so it's currently set as the geom being the tag to the master object.

-Thank you!