Need help with making rig face player at all times

Greetings everyone, I am working on a cutscene, and I need an npc to face the player all the time. I used cframe.lookat, which worked, but It ALWAYS faces the player, so its whole body would move to face towards the player.

heres a video example:
https://gyazo.com/56b09759aacbd74b8725dac6698dfcc9

and my code is very simple:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local runservice = game:GetService("RunService")

local rigroot = game.Workspace:WaitForChild("Rig"):WaitForChild("HumanoidRootPart")

runservice.RenderStepped:Connect(function()
	rigroot.CFrame = CFrame.lookAt(rigroot.Position,character:WaitForChild("HumanoidRootPart").Position)
end)

It’s in a local script inside starter player scripts.

what i want is for the rig face the character, but not like in the video, where it looks up. I tried using an align orientation constraint, but it didnt work out for me.

Thanks!

Change the “lookAt” parameter of CFrame.lookAt so that instead of looking exactly at the player, it looks at the players’ X and Z value, while keeping it’s own Y value.

rigroot.CFrame = CFrame.lookAt(rigroot.Position, Vector3.new(character:WaitForChild("HumanoidRootPart").Position.X, rigroot.Position.Y, character:WaitForChild("HumanoidRootPart").Position.Z))

Would suggest making character:WaitForChild(“HumanoidRootPart”) its own variable so this line of code is easier to read though :sob:

1 Like

Yea i just figured it out after reading the dev docs and stuff. Your solution is exactly what i was going to do.

this is what i did to protect my eyes:

runservice.RenderStepped:Connect(function()
	local rigPosition = rigroot.Position
	local characterPosition = character:WaitForChild("HumanoidRootPart").Position

	characterPosition = Vector3.new(characterPosition.X, rigPosition.Y, characterPosition.Z)

	rigroot.CFrame = CFrame.lookAt(rigPosition, characterPosition)
end)

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