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)
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)
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)