Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to tell if a player's head (or torso) is facing towards an NPC?

Asked by 3 years ago

I'm working on a model of SCP-096 and I need help knowing if the head (or in this case, torso) is facing towards the face of the SCP. The normal script uses the variables TargetTorso: the torso of the player it detects is near it (needs to be who looks at it) NoticeDistance: I think this might just be able to be taken away. Chasing: self-explanatory, goes into raging stage. and a bunch of other "targets". The old script goes as follows.

local NoticeDistance=8; local TargetTorso; for _,TargetModel in pairs(game:GetService("Workspace"):GetChildren())do if TargetModel.className=="Model"and TargetModel~=SCP096 and TargetModel.Name~=SCP096.Name and TargetModel:FindFirstChild("HumanoidRootPart")and TargetModel:FindFirstChild("Head")then local TargetPart=TargetModel:FindFirstChild("HumanoidRootPart"); local FoundHumanoid; for _,Child in pairs(TargetModel:GetChildren())do if Child and Child.ClassName=="Humanoid"and Child.Health~=0 then FoundHumanoid=Child; end; end; if TargetPart and FoundHumanoid and FoundHumanoid.Health~=0 and(TargetPart.Position-SCP096HumanoidRootPart.Position).magnitude<NoticeDistance then TargetTorso=TargetPart; NoticeDistance=(TargetPart.Position-SCP096HumanoidRootPart.Position).magnitude; AttackDebounce=true; spawn(function() Chasing=true;

--then the SCP starts raging and then chasing the TargetTorso until it kills it. I need help scripting a way to find if they are looking at his face (possible using LookVector, or LookVector:Dot), while having it work with the script itself.

2 answers

Log in to vote
0
Answered by 3 years ago

Use Raycasting, which can tell if a part is blocking its path or "ray". https://www.youtube.com/watch?v=CPcaJgQkxM8 here's a great video explaining the basics.

Ad
Log in to vote
0
Answered by 3 years ago

You could either use raycasting; or you could use a long straight weightless invisible part that would be part of the players default StarterCharacter model, have a script in it that sets a serverstorage boolvalue to true/false & then use an on Value.Changed system in the rest of your script.

Answer this question