-
What do you want to achieve? Keep it simple and clear!
I wan’t to edit my dot product script so that players behind a wall/part aren’t detected. -
What is the issue? Include screenshots / videos if possible!
My NPC has a script inside it that basically picks up players that enter its field of view.
My problem is that even if the player is behind a wall, the bot still thinks its in its FOV. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried looking tutorials on YouTube/the Dev Forum but nothing helped.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
--ServerScript placed inside of the NPC's Humanoid
function lolWalk()
local closestmane
local closesmaneMag = 1000000000000
for _, player in pairs(game.Players:GetPlayers()) do
if player.Character then
local hrp = player.Character.Torso
local hrpMagnitude = hrp and (script.Parent.Parent.Torso.Position - hrp.Position).Magnitude or math.huge
if closesmaneMag >= hrpMagnitude then
closesmaneMag = hrpMagnitude
closestmane = hrp
end
end
end
return closestmane
end
coroutine.resume(coroutine.create(function()
while wait() do
repeat wait() until lolWalk()
local torso = lolWalk()
local npc = script.Parent.Parent
local character = torso.Parent
local npcToCharacter = (character.Head.Position - npc.Head.Position).Unit
local npcLook = npc.Head.CFrame.LookVector
local dotProduct = npcToCharacter:Dot(npcLook)
if dotProduct > .5 then
--Char in POV
script.LookingAtPlayer.Value = true
print("in pov")
else
--Char isnt in POV
script.LookingAtPlayer.Value = false
print("not in pov")
end
end
end))
All help is appreciated!