Created
January 19, 2022 15:44
-
-
Save fallenblood7080/595d8e3d2060e58786c3e1d3c79c6e42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//script of FOV Tutorial(Unity) - https://youtu.be/ztdj0KUnGuY | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class fov_script : MonoBehaviour | |
{ | |
public float fovAngle = 90f; | |
public Transform fovPoint; | |
public float range = 8; | |
public Transform target; | |
void Update() | |
{ | |
Vector2 dir = target.position - transform.position; | |
float angle = Vector3.Angle(dir, fovPoint.up); | |
RaycastHit2D r = Physics2D.Raycast(fovPoint.position, dir, range); | |
if (angle < fovAngle / 2) | |
{ | |
if (r.collider.CompareTag("Player")) | |
{ | |
// WE SPOTTED THE PLAYER! | |
print("SEEN!"); | |
Debug.DrawRay(fovPoint.position, dir, Color.red); | |
} | |
else | |
{ | |
print("we dont seen"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment