Well I used this one Field of View script but I do not know how to fix it that it will check the character and also dead bodies like a withness system,this is the code:
local PlayerService = game:GetService(“Players”)
local NPC = script.Parent
local Range = 30 -- How far the NPC can see in studs.
local FOV = 70 -- The NPC's FOV in degrees.
local function GetCharacters()
local Characters = {}
for _, b in PlayerService:GetPlayers() do
table.insert(Characters, b.Character)
end
return Characters
end
local function CheckLineOfSight(Start, End)
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {NPC, GetCharacters()}
Params.FilterType = Enum.RaycastFilterType.Exclude
local Raycast = game.Workspace:Raycast(Start, End - Start, Params)
if Raycast then
return false
else
return true
end
end
local function FOVCast()
for _, b in PlayerService:GetPlayers() do
local Character = b.Character
if Character then
local NPCToCharacter = (Character.Head.Position - NPC.Head.Position).Unit
local NPCLookVector = NPC.Head.CFrame.LookVector
local DotProduct = NPCToCharacter:Dot(NPCLookVector)
local Angle = math.deg(math.acos(DotProduct))
local Distance = (NPC.HumanoidRootPart.Position - Character.HumanoidRootPart.Position).Magnitude
if Angle <= FOV and Distance <= Range and CheckLineOfSight(NPC.Head.Position, Character.Head.Position) then
else
end
end
end
end
while task.wait(1) do
FOVCast()
end
Can you guys fix it so it can like check other dummies in the field of view?