basically, im trying to find a way to detect if any humanoits is in NPC’s sight.
i’ve already implemented the Dot Product and Range system just not detecting if that humanoid thats getting detected is blocked by an obstacle or not.
im currently thinking of using raycast from npc position to the humanoid position to detect if theres an obstacle, if no then it will return the humanoid, if yes then no humanoids.
is there another way than raycasting? just wanna know
Hello, if you will try using raycast. I suggest you to check this script
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local primary = char.PrimaryPart or char:WaitForChild("HumanoidRootPart")
local cam = workspace.CurrentCamera
local function OnScreen(object)
local IsObsufcated = #cam:GetPartsObscuringTarget({object.Position},{object,char}) == 0
local _, OnScreen = cam:WorldToScreenPoint(object.Position)
return OnScreen and IsObsufcated
end
OnScreen(primary) -- should print true
made a more accurate version
loc…
Sorry for bad english
its from the npc itself and not the player, so using current camera is not possible
Its local script? 3000000000000
Try to understand what im trying to achieve on the original message, all the detections are from servers
I mean npc probably can’t see through walls. but if you meant npc fov, check this script.
Edit: If a player leaves, any other code you add to this script may break (Kind of obvious but just want to clarify for any new scripters who may stumble across this post)
@incognitobot_rblx 's works but you I you might have to change the value depending on how much you want your npc to see. :Dot() goes from -1 to 1, so if you want to have say 70 degrees of fov, you would have this (Code goes inside npc. You can undo the comments on the prints if you want a visual output, but you can also use t…
Ye you can check it on server
raycasting will be the most efficient solution here no real reason to avoid it