Need help with Player Rotation System

Every time the player’s head turns 45 degrees the HumanoidRootPart rotates 45 degrees but the way it’s coded it makes it all choppy, any fixes?

Here is what the script looks like.

local character = script.Parent
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local TweenService = game:GetService("TweenService")
local character = script.Parent
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local head = character:WaitForChild("Head")

game:GetService("RunService").RenderStepped:Connect(function()
	local camRender = workspace.CurrentCamera.CFrame
	local x, y, z = camRender:ToOrientation()
	local diff = humanoidRootPart.Orientation.Y - math.deg(y)
	if (diff > 45 and diff < 315) or (diff < -45 and diff > -315) then 
		humanoidRootPart.CFrame = humanoidRootPart.CFrame:Lerp(CFrame.new(humanoidRootPart.Position) * CFrame.Angles(0, y, 0), 1)
	end
end)
1 Like

The solution is pretty simple considering that you are already using renderstepped, and you’re definitely on the right track.

All you have to do is to use the delta provided by renderstepped for our alpha to smooth out the rotation, and instead of changing the cframe of the hrp only when our difference is true, we can set a target cframe, and then lerp to that every frame.

local character = script.Parent
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local TweenService = game:GetService("TweenService")
local character = script.Parent
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local head = character:WaitForChild("Head")

local TargetAngle = CFrame.new()
local EaseTime = .4 --change to however long you want the ease to be

game:GetService("RunService").RenderStepped:Connect(function(dt)
	local camRender = workspace.CurrentCamera.CFrame
	local x, y, z = camRender:ToOrientation()
	local diff = humanoidRootPart.Orientation.Y - math.deg(y)

	humanoidRootPart.CFrame = humanoidRootPart.CFrame:Lerp(CFrame.new(humanoidRootPart.CFrame.Position) * TargetAngle, 1/EaseTime * dt)
	if (diff > 45 and diff < 315) or (diff < -45 and diff > -315) then
		TargetAngle = CFrame.Angles(0, y, 0)
	end
end)
1 Like

Works perfectly how I wanted it to be, thank you.

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