- Home /
Answer by Berenger · Jun 26, 2012 at 05:07 AM
I'g go for, 1) proximity check (sphere trigger or Physics.OverlapSphere every x seconds) 2) Obstacles (Raycast) and 3) Angle between the forward vector and the AI -> player vector.
cookie130 : Can you put that in a little simpler terms ?
It's easy to use simple terms to explain AI but I'll give it a shot.
First, you need to make sure the player is close enough, no matter which direction the player is. This can be achieved by using the function Physics.OverlapSphere which returns all the colliders in a given sphere at a given time. There is no need to do it every frame, so I suggested using a coroutine to call that function every x seconds.
Then, if step one succeeded, you need to make sure there isn't a wall between the enemy and the player, in which case, the player is hidden. You can use Raycast from the enemy to the player to check if something is in the way.
Finally, You need to check if the enemy is looking more or less in the direction of the player. He doesn't have eyes behind the head, does he. You can do that by measuring the angular distance between the forward of the enemy and the vector from the enemy to the player. If it's low enough, the player is visible.
Your answer
Follow this Question
Related Questions
Raycast target line of sight 1 Answer
Line of sight audio 2 Answers
SphereCastAll sees for miles 2 Answers
Unity, 2D AI Error 0 Answers