How can i make the character rotates toward the camera?

I am making my player turn towards the camera with lerp to make a smooth movement at the beginning but to remain firm when he is already facing the camera

I’m trying with lerp but my character rotates infinitely

my code here:

local camera = workspace.CurrentCamera

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local root = char:WaitForChild("HumanoidRootPart")
local head = char:WaitForChild("Head")


game:GetService("RunService").RenderStepped:Connect(function()
	if root then
		local cameraDirection = camera.CFrame.LookVector

		root.CFrame = root.CFrame:lerp(root.CFrame * CFrame.Angles(0,cameraDirection.Y,0),.75)
	end
end)

Try this instead:

game:GetService("RunService").RenderStepped:Connect(function()
	if root then		
		root.CFrame = root.CFrame:lerp(CFrame.lookAt(root.CFrame.Position, camera.CFrame.Position) , 0.1)
	end
end)

It works but the player turns looking directly at the camera, and when I look up or down the character moves weird

We could discard the Y-axis entirely to avoid that:

game:GetService("RunService").RenderStepped:Connect(function()
	if root then		
		local lookVector = (camera.CFrame.Position - root.Position) * Vector3.new(1, 0, 1)		
		root.CFrame = CFrame.lookAt(root.Position, root.Position + lookVector)
	end
end)
1 Like

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