AI Field Of View

I am trying to make a game kinda like SCP 3008. And I wanna make a custom AI that checks if the player is within the AI’s field of view. I have seen a post about how to check if an object is within the field of view but that only works with a given position and I need it to work for all players.

Basic said: How would I make a script for an AI that checks if a player is within its Field of View.
I cannot include any script since I have no idea how to do this.

1 Like

The tutorial told to do it with one point, the way you do it to every players is by getting their character’s HumanoidRootPart.
For example:

for _, plr in pairs(game.Players:GetPlayers()) do
      local Char = plr.Character
      local Humr = Char.HumanoidRootPart
      -- the rest of your script
end

I suppose you already knew about :Dot() and .Magnitude so I wont talk about that.

Yeah i know about those im just concerned that making a constant loop like this would kill the server if i wear to add 50 AI’s at once

Then what about of hitbox system.

You mean if the monster is visible on the players screen the monster jumpscares you?

Do you mean Touched? I considered that but again Touched isn’t really reliable.

I was thinking of workspace:GetPartsInPart() every 5 secs

You may want to try raycasting from the ai’s head to every player’s humanoidrootpart, so that way if there’s something blocking them then the ai will only target player’s that were seen

No im trying to do it from the AI’s field of view. To check if its looking at a player and if it is it will hunt him

Im planning to do that: if its find a player within the field of view ill shoot a raycast to check if there’s something infront.

Thats pretty easy i know a system for that, also with safe zones so the ai doesnt kills you and also that the AI has a pathfinding system.


This here is the code that will check if a object is within field of view. But it can only check for 1 Specified object

1 Like

Do you know what the systems called? Id like to see its code if possible

https://www.roblox.com/library/7819165895/Ph4ntoms-AI-New-Features
https://www.roblox.com/library/7895460422/THE-MIMIC-KIT-Safe-Zone

You can try to just detect the player’s humanoidrootpart position relative to the position of your ai’s head with cframes then once you have the players that are in front of the ai, raycast to check if there’s any obstructions

Alright thanks ill check this and reply with the results.

Watch a yt tutorial to make your own monster and stuff

In this case, :GetPartsInPart() is useful in order to make safe zones

Use a for loop to reiterate over player’s characters

He was wondering if it would kill the server with 50 loops run at a same time.