Hello there!
I’ve followed a two part tutorial on how to create viewmodels by using the players actual arms instead of having to manually create fake arms for the viewmodel. Anyway, the second part of the tutorial explained how to add swaying to the viewmodel.
The issue however is that, as seen in the video, you can see the arms are noticeably choppy and not smooth.
Anyway, I was planning on replacing the entire swaying code the tutorial used for a brand new one using a springe module. (This one specifically.) Although I don’t know how to. Any examples?
local Character = script.Parent
--//Services\\--
local RS = game:GetService("ReplicatedStorage")
local RunS = game:GetService("RunService")
--//Viewmodel\\--
local VM = RS.VM:Clone()
VM.Parent = workspace.CurrentCamera
--//Swaying\\--
local runMult = 10
local walkMult = 4
local swaySpeed = .1
local returnSpeed = .1
local SmoothingMult = .5
--Offsets
local OFFSET = 0
local X = 0
local Y = 0
--Functions
local Sine = 0
local function getCframe(cframe)
local sx, sy, sz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = cframe:GetComponents()
local X = math.atan2(-m12, m22)
local Y = math.asin(m02)
local Z = math.atan2(-m01, m00)
return X,Y,Z
end
--Other variables
local val = 0
local moving = false
--//Actual viewmodel function stuff or something idk\\--
RunS.RenderStepped:Connect(function()
--VM:PivotTo(workspace.CurrentCamera.CFrame + workspace.CurrentCamera.CFrame.LookVector * 0)
--Arms stuff
Character["Right Arm"].LocalTransparencyModifier = 0
Character["Left Arm"].LocalTransparencyModifier = 0
--Moving arms to viewmodel
if Character.Torso:FindFirstChild("Right Shoulder") and Character.Torso:FindFirstChild("Left Shoulder") then
Character.Torso["Right Shoulder"].Part0 = VM.Torso
Character.Torso["Left Shoulder"].Part0 = VM.Torso
end
--Swaying
OFFSET = script.OFFSET.Value
X = script.X.Value
Y = script.Y.Value
local pcframe = workspace.CurrentCamera.CFrame + workspace.CurrentCamera.CFrame.LookVector * OFFSET + workspace.CurrentCamera.CFrame.RightVector * X + workspace.CurrentCamera.CFrame.UpVector * Y
local lerpedRot = VM.PrimaryPart.CFrame:lerp(pcframe,SmoothingMult)
local _,_,_,m11,m12,m13,m21,m22,m23,m31,m32,m33 = lerpedRot:components();
local ogPos = pcframe.p;
local newCf = CFrame.new(ogPos.x,ogPos.y,ogPos.z,m11,m12,m13,m21,m22,m23,m31,m32,m33)
VM.PrimaryPart.CFrame = newCf;
Sine = math.sin(val)
if Character.Humanoid.MoveDirection ~= Vector3.new(0,0,0) then
if Character.Sprint.Sprinting.Value == false then
val += .2
game.TweenService:Create(script.X, TweenInfo.new(swaySpeed,Enum.EasingStyle.Linear,Enum.EasingDirection.Out), {Value = Sine/runMult}):Play()
if Sine < 0 then
game.TweenService:Create(script.Y, TweenInfo.new(swaySpeed,Enum.EasingStyle.Linear,Enum.EasingDirection.Out), {Value = -Sine/runMult}):Play()
else
game.TweenService:Create(script.Y, TweenInfo.new(swaySpeed,Enum.EasingStyle.Linear,Enum.EasingDirection.Out), {Value = Sine/runMult}):Play()
end
else
val += .4
game.TweenService:Create(script.X, TweenInfo.new(swaySpeed,Enum.EasingStyle.Linear,Enum.EasingDirection.Out), {Value = Sine/walkMult}):Play()
if Sine < 0 then
game.TweenService:Create(script.Y, TweenInfo.new(swaySpeed,Enum.EasingStyle.Linear,Enum.EasingDirection.Out), {Value = -Sine/walkMult}):Play()
else
game.TweenService:Create(script.Y, TweenInfo.new(swaySpeed,Enum.EasingStyle.Linear,Enum.EasingDirection.Out), {Value = Sine/walkMult}):Play()
end
end
else
game.TweenService:Create(script.Y, TweenInfo.new(returnSpeed,Enum.EasingStyle.Linear,Enum.EasingDirection.Out), {Value = 0}):Play()
game.TweenService:Create(script.X, TweenInfo.new(returnSpeed,Enum.EasingStyle.Linear,Enum.EasingDirection.Out), {Value = 0}):Play()
end
end)