#fov
1 messages · Page 1 of 1 (latest)
making a thread
reposting the code --
float angle = Vector3.Angle(eyeVec, toPlayer);
if (angle < fov) {
if (!Physics.Raycast(...)) {
// player is in FOV, nothing is in the way!
}
}
This measures the angle between two vectors:
- a vector in the direction the enemy is looking
- a vector from the enemy to the player
That includes both horizontal and vertical differences
It won't match the rectangular shape you showed, though
none of these. it would be transform.forward for whatever transform represents the enemy's head
er
oh alright
maybe visionPosition, then !
yup
visionPosition.forward
then Vector3 toPlayer = player.transform.position - visionPosition.position;
If the enemy is looking right at the player, the angle between the two vectors will be zero
so like this?
im a bit lost
your angle calculation is wrong
it's trying to find the angle between the forward vector of the view transform and...the player's position
those are two different things
notice how your code isn't actually using toPlayer
compute the angle between visionPosition.forward and toPlayer
@obsidian marlin how would you go about making the fov