Making NPC's head look at player while it moves

I am trying to make an NPC’s head look at a player’s character. The NPC is supposed to look at the player as it is following the player. Setting the head’s CFrame achieves the desired effect (with CFrame.lookAt), but it makes the NPC unable to move. I’ve also tried changing the neck Motor6D’s C0, but that causes the head to face either left or right and then snap at the player before going back.

-- Changing neck C0
-- Both functions are called every 0.1 seconds
local function lookAtCharacter(target)
	local neck = npc.Head.Neck
	local unitVector = (primaryPart.CFrame.Position - target.PrimaryPart.Position).Unit
	neck.C0 *= CFrame.new(Vector3.new(0, 0, 0), unitVector) * CFrame.Angles(0, -math.rad(primaryPart.Orientation.Y), 0)
end

-- Setting the CFrame
local function lookAtCharacter(target)
    npc.Head.CFrame = CFrame.lookAt(npc.Head.Position, target.PrimaryPart.Position)
end

I’ve found a solution here:
https://devforum.roblox.com/t/making-npcs-head-face-player-correctly-no-matter-their-rotationorientation/766998

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.