How to I rotate I make an NPC rotate to a player?

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)
1 Like

Use CFrame.new() and only make it so it doesnt use the y value to look at you

local playercharacter = game.Players.librashards.Character
script.Parent.HumanoidRootPart.CFrame = CFrame.new(script.Parent.HumanoidRootPart.Position, Vector3.new(playercharacter.HumanoidRootPart.X, script.Parent.HumanoidRootPart.Position.Y, playercharacter.HumanoidRootPart.Position.Z))

td;lr: exclude the Y value

1 Like

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

oh well in that case just set the y and z values to what it currently is, and set x to what you want it.

1 Like
CFrame.lookAt(Animatronic.Head.Position,  Vector3.new(char.Head.Position.X, Animatronic.Head.Position.Y, char.Head.Position.Z))

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.

1 Like