Npc view problem

I have been wanting to make an NPC for a while now but I don’t want to just put a part around the NPC and make that the detection box I want it to have a view.

I want to have a field of view like this

So it cannot see through walls.
But I don’t know how to go about this.

1 Like

Something like Creating a field of sight but with obstruction? or do you actually want it to visually look like the images you provided or do you want both


i’m not sure i completely understand what you are trying to do, but you might want to check out the raycasting algorithm in: 2d Visibility and it can be “easily” expanded to 3d

Exactly like creating a field of sights Thanks!

1 Like

You could try using a part attached to the npc and if it touches a player, raycast to see if they are on the other side of a wall. Or, use magnitude to detect when a player is within a certain distance, find out if they are within a certain angle of the npc, and then raycast. That’s if you don’t want to rely on .Touched.