NPC that follows player, but only when it's in view

So, I can’t find a direct answer to this question, so I’ll break it down.

Long Explanation:
I want an NPC that follows the player. However, I want it to only follow the player when the player is in the NPC’s view. However, the problem I’m having, is that I want the NPC to detect behind, and to the sides of it too, the current script I have only detects face-on raycasts.

Short Explanation:

1 Like

Shoot a raycast from the npc to the player, if the raycast hits the player the npc can see it

Just do a raycast straight from the NPC to the character.

I once created a 313 line piece of code using this strategy for killer NPCs. Although, it didn’t work too well.

Also, @MrOnlyKemal sent the post first, so mark him as the solution.

2 Likes