AngleToAngle
Introduction
Returns the shortest distance to rotate from the first argument angle to the second argument angle. All values are in radians. The absolute value of the return value will never be greater than PI (half of a circle). If the value is positive then the shortest distance is achieved by rotating counterclockwise. If the value is negative then the shortest distance is achieved by rotating clockwise.
Turning towards angle
The AngleToAngle method can be used to turn one object toward a direction. The following code creates a Sprite which will turn toward the point where the cursor is located. Add the following using statements:
Add the following at class scope:
Add the following to Initialize after initializing FlatRedBall:
Add the following to Update:
Range Checks
The AngleToAngle can be used to check if one object is within an angle range. For example, you may be making a stealth game where the player must avoid being seen by enemies. We'll assume that the enemies have a property called ViewAngle which represents the edge-to-edge angle that the enemies can see. We'll also assume that this code has calculated the angle from the enemy to the player. For information on how to calculate this, see this page.
Last updated