View Single Post
Old 06-28-2009, 10:43 PM   #5 (permalink)
DiNoGames
zB Programmer
Member
 
DiNoGames's Avatar
 
Join Date: May 2008
Location: Bremen, germany
Posts: 581
DiNoGames is a name known to allDiNoGames is a name known to allDiNoGames is a name known to allDiNoGames is a name known to all
Send a message via Skype™ to DiNoGames
Default

Quote:
Originally Posted by JulianDave View Post
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
__________________

Valgard's Fate Blog







DiNoGames is offline   Reply With Quote