Hi, I need help with the rotation of an npc to a player. I know how to use the LookAt() Function but the thing is when used on my humanoid root part it makes the
npc
move up when the player gets too close.
I forgot how to make it so you can only make the npc rotate only horizontally
Here’s my code
local runservice = game:GetService("RunService")
local char = script.Parent
local Animatronic = game.Workspace.Farmer
runservice.Stepped:Connect(function()
local Distance = (char.Head.Position - Animatronic.Upperjaw.Position)
local Look = Animatronic.HumanoidRootPart.CFrame.LookVector
local LookPosition = Distance:Dot(Look)
if LookPosition > .5 then
print("There you are!")
Animatronic.HumanoidRootPart.CFrame = CFrame.LookAt(Animatronic.Head.position, char.Head.Position)
else
print("Where you at?!?")
end
end)
How would I exclude it? Setting it to 0 doesn’t fix it. and I think I need to find a way to change the CFrame’s x value only and not the value of the player
Should be lookAt not LookAt and these are the arguments you’re looking for. You construct a new Vector3 value using the target position’s X and Z components and maintain the origin’s Y component.