Collision detection in 3D

Coordinator
Sep 12, 2008 at 9:03 PM
This was an interesting problem.  After much googling, I selected to use the BoundingSphere method: get the BoundingSpheres of the original model meshes, move them with the model to its current location, and check if they intersect with the BoundingSpheres of another model.  The reason why the BoundingSpheres have to be moved by the developer is because the BoundingSphere property of a ModelMesh doesn't move with the model; XNA leaves it to the developer to compensate for this.

I have an abstract class representing a 3D object in my world, and I modified that to expose the collection of ModelMeshes as a public property.  I then wrote a public method which accepted a parameter of another object of the same type.  In this method, I went through each ModelMesh of the class, grabbed the BoundingSphere of each and incremented the center by the current position of the object.  I then did the same with the parameter object and checked to see if any of the BoundingSpheres intersected.

Although this was a simple method to check for model collision, the problem is that the BoundingSpheres don't wrap tightly to the model, so even if the models don't collide, the collision check condition may evaluate to true.