How Do I Rotate The Player Smoothly?

So all I’m trying to do is rotate the player’s character to follow the mouse. Currently it works, but if you were to move the cursor quickly, my method is not able to keep up. The character rotates just ever so slightly behind creatting a “choppy” effect.

Here is my function that rotates the player,

--- RenderStep ---
RunService.RenderStepped:Connect(function()
	local rx, ry, rz = CurrentCamera.CFrame:ToOrientation()
	HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.CFrame.Position) * CFrame.fromOrientation(0, ry, 0)
end)

To be clear, I’m searching for a fix/alternative to achieve smoother rotation. Thanks for all your help!

2 Likes

I would recommend using BodyGyro.

^^ a similar post

1 Like

Is BodyGryo in the process of being deprecated? or should I still go on with it?

Edit: It also appears that this “AngularOrientation” link leads to an error.

You might be able to, but am not sure as I haven’t used AngularOrientation before.
Although BodyGyro works fine for me and pretty sure AngularOrientation requires Attachments
to be used. Probaly won’t get deprecated as it still has it’s uses tbh

1 Like

I can’t seem to get it working right… Have I set it up correctly?

--- Bodygyro ---
local GyroBody = Instance.new("BodyGyro")
GyroBody.Parent = Player.Character.LowerTorso


--- RenderStep ---
RunService.RenderStepped:Connect(function()
    GyroBody.CFrame = CFrame.new(HumanoidRootPart.CFrame.Position, Vector3.new(0, HumanoidRootPart.CFrame.Position.Y, 0))
end)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local camera = workspace.CurrentCamera

local rs = game:GetService("RunService")
local ts = game:GetService("TweenService")

rs.RenderStepped:Connect(function()
	local rx, ry, rz = camera.CFrame:ToOrientation()
	local tween = ts:Create(hrp, TweenInfo.new(0.5), {["CFrame"] = CFrame.new(hrp.CFrame.Position) * CFrame.fromOrientation(0, ry, 0)})
	tween:Play()
end)

Tweens are great for smooth animations/transitions.

1 Like
local index = 0.2 --smoothness
RunService.RenderStepped:Connect(function()
   local rx, ry, rz = CurrentCamera.CFrame:ToOrientation()
   local final = CFrame.new(HumanoidRootPart.CFrame.Position) * CFrame.fromOrientation(0, ry, 0)
   HumanoidRootPart.CFrame = HumanoidRootPart.CFrame:Lerp(final, index)
end)
5 Likes