#fov

1 messages · Page 1 of 1 (latest)

obsidian marlin
#

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

last elk
#

so which one would be the eyeVec

obsidian marlin
#

none of these. it would be transform.forward for whatever transform represents the enemy's head

#

er

last elk
#

oh alright

obsidian marlin
#

maybe visionPosition, then !

last elk
#

yup

obsidian marlin
#

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

obsidian marlin
#

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

obsidian marlin
# last elk

notice how your code isn't actually using toPlayer

#

compute the angle between visionPosition.forward and toPlayer

last elk
#

@obsidian marlin how would you go about making the fov

last elk
# last elk

like if you needed to look similar to this

#

would you even do it with a raycast

#

or like a collider

obsidian marlin
#

fov is just a number

#

if the angle is lower than fov, the player is in the enemy's field of view