So, I got some polygons out there as static walls. And I got some bullets flying around. I wanted to replace the collision detection of the engine with that of my own, since I don't want bullets bouncing off walls and people, I want them to hit
and do damage (if applicable).
So first I add in my own collision delegate to the Geom.OnCollision event:
this.m_geom.OnCollision += new CollisionEventHandler(Projectile_Collision);
I throw in my "do damage" method and it works. Now the problem is I have to get rid of the bullet, here's where the problem happens.
When there is a collision, with whatever, I want to destroy my projectile. The method I have doing that is this:
public override void Destroy()
m_sprite = null;
m_level = null;
m_targetUnit = null;
Below is the base.Destroy from above:
public virtual void Destroy()
if (m_body != null)
m_body = null;
if (m_geom != null)
//m_geom.InSimulation = false;
m_geom = null;
Now, my geometries for the walls are close together, and I've noticed that if the projectile collides at a spot where two walls meet, then I get a "KeyNotFoundException was unhandled" message in the DistanceGrid.Collide(...) method.
Here are some images:
I'm not sure if it's a bug or just something I'm doing wrong. I imagine it happens because there are two collisions on the corner and I remove the shot in the first one and it's not available for the second one. If there's a better way of removing
the geometry and body from the simulator please let me know!