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
RED = NPC
GREEN = 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
Do you think raycast it more optimization or this way?
so if we read this
https://developer.roblox.com/en-us/api-reference/property/BasePart/CanTouch
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
You can use either magnitude or region3
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.