MSDN suggested this, but I'm worried about it slowing down the game when there are a lot of objects to check:
for (int i = 0; i < enemy.Length; i++)
{
if (enemy[i].isActive)
{
BoundingSphere enemySphere =
new BoundingSphere(enemy[i].position,
enemy[i].Model.Meshes[0].BoundingSphere.Radius *
enemy[i].modelBoundingConstant);
for (int j = 0; j < bulletList.Length; j++)
{
if (bulletList[j].isActive)
{
BoundingSphere bulletSphere = new BoundingSphere(
bulletList[j].position,
bulletModel.Meshes[0].BoundingSphere.Radius);
if (enemySphere.Intersects(bulletSphere))
{
enemy[i].health -= 10;
bulletList[j].isActive = false;
break; //no need to check other bullets
}
}
}
}
}
Nested looping like this just doesn't seem like the most efficient way to check if a bullet connects with an enemy. Is there a better way?