How do I make the player's arms smoothly point to the mouse?

So I want a way for the players arms to face towards the mouse smoothly. I don’t want the arms to just instantly snap.

How would I make the arms slowly point towards the mouse?

Here’s my current code:

RunService.RenderStepped:Connect(function()
	local X = -(math.asin((Mouse.Origin.p - Mouse.Hit.p).unit.y))
	
	-- Right shoulder
	local _, Y, Z = RightShoulder.C0:ToEulerAnglesXYZ()
	RightShoulder.C0 = CFrame.new(RightShoulder.C0.Position) * CFrame.Angles(X, Y, Z)

	-- Left shoulder
	local _, Y, Z = LeftShoulder.C0:ToEulerAnglesXYZ()
	LeftShoulder.C0 = CFrame.new(LeftShoulder.C0.Position) * CFrame.Angles(X, Y, Z)
end)
1 Like

you could try lerping the CFrames

I have tried that, but that only seems to give the arms an offset and breaks it terribly (rather than slowly turning towards the mouse)

local PreviousRSCFrame = CFrame.new()
local PreviousLSCFrame = CFrame.new()

RunService.RenderStepped:Connect(function()
	local X = -(math.asin((Mouse.Origin.p - Mouse.Hit.p).unit.y))
	
	-- Right shoulder
	local _, Y, Z = RightShoulder.C0:ToEulerAnglesXYZ()
	RightShoulder.C0 = (CFrame.new(RightShoulder.C0.Position) * CFrame.Angles(X, Y, Z)):Lerp(PreviousRSCFrame, 0.5)
	
	local PreviousRSCFrame = (CFrame.new(RightShoulder.C0.Position) * CFrame.Angles(X, Y, Z))

	-- Left shoulder
	local _, Y, Z = LeftShoulder.C0:ToEulerAnglesXYZ()
	LeftShoulder.C0 = CFrame.new(LeftShoulder.C0.Position) * CFrame.Angles(X, Y, Z):Lerp(PreviousLSCFrame, 0.5)
	
	local PreviousLSCFrame = (CFrame.new(LeftShoulder.C0.Position) * CFrame.Angles(X, Y, Z))
end)

are you rotating the arms on all 3 axis?

yes. It worked well before. It only broke when I applied :Lerp() to the CFrames

I’m sorry I have No clue on what to do from here.

The lerp formula is odd, you should only lerp the motor6D.C0.Rotation:lerp(newgoalRotation, 0.2)

Make sure it only has rotation and no position components

You could try using tweens

local TweenService = game:GetService("TweenService") 

RunService.RenderStepped:Connect(function()
	local X = -(math.asin((Mouse.Origin.p - Mouse.Hit.p).unit.y))
	
	-- Right shoulder
	local _, Y, Z = RightShoulder.C0:ToEulerAnglesXYZ()

	TweenService:Create(
		RightShoulder,
		TweenInfo.new(0.4),
		{C0 = CFrame.new(RightShoulder.C0.Position) * CFrame.Angles(X, Y, Z)}
	):Play()

	-- Left shoulder
	local _, Y, Z = LeftShoulder.C0:ToEulerAnglesXYZ()

	TweenService:Create(
		LeftShoulder,
		TweenInfo.new(0.4),
		{C0 = CFrame.new(LeftShoulder.C0.Position) * CFrame.Angles(X, Y, Z)}
	):Play()
end)