I've been trying for a while now to convert this script:
https://devforum.roblox.com/t/how-to-create-a-realistic-npc-eyesight-system/2456522
into a system that detects NPCs and not players.
Here is what I got so far before getting stumped:
local collectionService = game:GetService("CollectionService")
local TeamA = collectionService:GetTagged("TeamA")
local range = 650
local viewAngle = 70
local lastEnemySpotted
local function getNPCs()
local NPCs = {}
local getNPC = collectionService:GetTagged("NPCs")
for index, getNPCs in getNPCs do
table.insert(NPCs, getNPC)
end
return NPCs
end
local function sightRaycast(TeamA, start, finish)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {TeamA, getNPCs()}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local ray = workspace:Raycast(start, (finish - start), raycastParams)
if ray then
return true
else
return false
end
end
Introduction Hello everyone! In this tutorial, I’m going to teach you how to create a realistic NPC eyesight system so that NPCs can see and detect players and other objects. For example, you could use this to make a guard detect a player. Steps Create a script in ServerScriptService and name it whatever you’d like. This script will cont...