Guest User

Untitled

a guest
Dec 16th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.41 KB | None | 0 0
  1. bool isWithinAngle(Vector2 playerPos, float playerRotation, Vector2 checkPos, float maxAngle)
  2. {
  3.     Vector2 difVector = playerPos - checkPos;
  4.  
  5.     float radRotation = (float)Math.Atan2(difVector.Y, difVector.X);
  6.     float degRotation = MathHelper.ToDegrees(radRotation);
  7.  
  8.     if (Math.Abs(degRotation - playerRotation) < maxAngle)
  9.     {
  10.         return true;
  11.     }
  12.     else
  13.     {
  14.         return false;
  15.     }
  16. }
Add Comment
Please, Sign In to add comment