- Home /
Visual Enemy FOV?
Hey y'all. I need help getting a visual field of view for an enemy. As of right now, I just have a filled sprite that I'm rotating and basically setting up before the game starts lol. I have my field of view script below. So what I'm trying to do is that if I set field of view to say 30, the visual field of view would start like in front of the enemy (the dotted line) and it would open up depending on the enemy's fov. So if the fov is 180, the whole front part is open if that makes sense.
Basically, there's a line where the enemy is looking forward and it opens up based on the FOV of the enemy. I just want it to open up based on the fov. I hope the picture explains it. The visual field of view (the sprite) would expand from the middle like how the yellow arrows show it.
public float fieldOfVision;
private Transform player;
private void Update()
{
player = GameObject.FindGameObjectWithTag("Player").transform;
Vector3 direction = player.position - this.transform.position;
float angle = Vector3.Angle(direction, this.transform.forward);
if (Vector3.Distance(player.position, this.transform.position) < sightRange && angle < fieldOfVision)
{
direction.y = 0;
this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(direction), speed); }
}
Thanks for the help
Your answer
![](https://koobas.hobune.stream/wayback/20220613015240im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Safe area from enemies 1 Answer
Can't click gameobject when over another trigger? 1 Answer
Sprite Diffuse shader not affected by point lights 1 Answer
audio trigger keydown 1 Answer