Quote:
Originally Posted by JulianDave
distance = Math.Sqrt(Math.Pow(PlayerPosition.X - AlienPosition[i].X, 2) + Math.Pow(PlayerPosition.Y - AlienPosition[i].Y, 2));
|
There are built-in functions to calculate distances of several types like:
- float MathHelper.Distance(float, float) (to get the non negative distance between two values)
- several overloads of Vector2.Distance (to get the distance between two 2D positions)
- several overloads of Vector3.Distance (to get the distance between two 3D positions)
You can also use BoundingSpheres for the purpose you are explaining here. BoundingSpheres and BoundingBoxes have built-in collision detection routines.
So your calculation is a good start, but XNA has all this stuff built in. You don't have to reinvent the wheel