/// <summary> /// Method that checks if the CCTV camera can see the player. /// </summary> /// <param name="entityPos">Position</param> /// <returns>True if the CCTV camera sees the player, false if not</returns> private bool CanSee(out Vector2 entityPos) { // The distance to the player var dis = Vector2.Distance(Position, player.Position); //Check if player is within view range if (dis < SightRange) { //Check to see if the guard is looking at the player var degrees = Math.Abs(MathHelper.ToDegrees(Rotation) - (90 + MathHelper.ToDegrees(MathExtensions.AngleBetween(Position, player.Position)))); if (degrees <= (SightFOV / 2) || degrees >= (360 - (SightFOV / 2))) { //Check to see if nothing blocks view of the player Collider hit; bool tilemap; // Check if the player is in the CCTV camera area if (Collider.RaycastAny(Position, player.Position, out hit, out tilemap, Tag)) { if (hit != null && hit.Entity.Tag.Equals("Player")) { entityPos = hit.Entity.Position; return(true); } } } } entityPos = Vector2.Zero; return(false); }
public bool IsVisible(Point viewPoint) { var angle = MathExtensions.AngleBetween(viewPoint, this); return(angle <= 90); }