What's the best way to make NPC field of view

Hello, recently I’m learning about AI. So now I’m trying to let my AI detect players in his FOV.
So I made it through ray cast but I think there’s better ways to do it with
And I’m searching now to find a better way to make FOV, what is your thoughts ?

there are a few ways you can do this but the way i like to do it is with a invisible ball


so i weld a invisible ball in front of the NPC and when the character touches it we know the player has entered the NPC’s line of sight

1 Like

Do you think raycast it more optimization or this way?

so if we read this

so if your leaving parts in your workspace with CanTouch and CanCollide turned on your losing performance all the time but that does not make us go and turn CanTouch and CanCollide off for everything

if you do raycasting or magnitude or spatial-query your going to have to keep doing it over and over and over again forever and i believe Roblox has a lot better optimisations with there touch events

1 Like

You can use either magnitude or region3

1 Like

Thanks you. I appreciate your help.

If you specifically need the detection of objects in a FOV then you could use the dot product of the unit lookvector of the AI and the unit direction between the AI and target. Obviously raycast too for any obstacles.