Remove arm stuttering

I recently created a script that makes the character’s upper torso move up and down with the camera, so that any tool it has equipped always points towards the camera. It does this by modifying the waist’s Motor6D.

the problem is that despite the code being run on the client side, in a renderStepped function. the movement lags behind the camera and moving it too fast causes it to spaz out. I expected it to be completely smooth since there should be no latency. is there something i can to remove it? Here’s the code:

local cam = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local RunService = game:GetService("RunService")
--local look = game:GetService("ReplicatedStorage").Look

local char = plr.Character or plr.CharacterAdded:Wait()
local upperTorso = char:WaitForChild("UpperTorso")
local hrp = char:WaitForChild("HumanoidRootPart")
local head = char:WaitForChild("Head")

local waist = upperTorso:WaitForChild("Waist")

local y = waist.C0.Y

RunService:BindToRenderStep("UpdateLoop", Enum.RenderPriority.Camera.Value + 1, function()
	if waist then
		local camDirection = cam.CFrame.LookVector
		local angle = math.deg(camDirection:Angle(hrp.CFrame.LookVector, cam.CFrame.RightVector))
		--look:FireServer(angle)
		waist.C0 = CFrame.new(0, y, 0) * CFrame.Angles(math.rad(-angle),0,0)
	end
	
	char.Humanoid.CameraOffset = (hrp.CFrame + Vector3.new(0, 1.5, 0)):PointToObjectSpace(head.Position)
end

Use lerp to do that.
Basically:

local FinalCFrame = -- cf
waist.C0 = waist.C0:Lerp(FinalCFrame,deltatime*responsiveness)
1 Like

Maybe use .RenderStepped? Or a higher priority.

1 Like

already tried both, same issue

Turns out, it was the HumanoidRootPart and CameraOffset itself that was stuttering, making the camera stutter behind the character as well.

Fixed it by first updating the RootPart’s CFrame to point in the same direction as the camera’s every frame to remove the stuttering caused by it, then instead of using CameraOffset, I updated the camera’s CFrame and Focus directly.

Code:

RunService:BindToRenderStep("CameraLoop", Enum.RenderPriority.Camera.Value + 1, function(dt)
	local look = (cam.CFrame.LookVector * Vector3.new(1, 0, 1)).Unit

	local cf = CFrame.new(hrp.CFrame.Position, hrp.CFrame.Position + look)
	hrp.CFrame = cf
	
	local camCframe = cam.CFrame
	
	local offset = (head.CFrame.Position - camCframe.Position)
	camCframe += offset

	cam.CFrame = camCframe
	cam.Focus += offset
end)

Result:

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