How would you make NPCs have a limited view distance?

In a nutshell, a straightforward way to do this is to use the NPC’s head part’s CFrame.LookVector as the direction the NPC is looking, and take the dot product with the vector given by (player Head position - NPC Head position). If the dot product is negative, the player is behind the NPC. In this simplified example, the NPC’s field of view id a perfect hemisphere in the direction their head is facing. And of course you can check line of sight to other body parts of the player as well, I just used the head as an example.

To fine tune this–e.g. to give the NPC a narrower or wider field of view, or to make vertical field of view different from horizontal–requires good understanding of exactly what the vector dot product represents, geometrically, and will require some reading and experimentation as others have noted already.

1 Like