FPS Arms swaying is noticeably choppy

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)

In that tutorial, was it smooth for the person who made it?

I cant tell if anything other than all the checks being done is causing the swaying to be a bit glitchy

Sadly, the part 2 tutorial seems to be a bit rushed as it only explained what parts of the code does and how to set it up (Assuming which you used the model he made which I did end up using albeit tweaked a bit for personal preference).

The quality is also worse than part 1.

EDIT: Also, if you want to see part 2 of the tutorial, here it is: https://www.youtube.com/watch?v=eVHL0gX4Leg&t=26s

1 Like

Must means he must’ve got the same results as you since I just skimmed thru and he didn’t show any testing footage

It might have something to do with the math being done but I know absolutely nothing about trigonometry or matrices so I can’t really tell

Alright then. Well, I did found this DevForum post here which used the spring module I’m currently using to fix the choppiness issue.

1 Like

Ya from the title of the post I have a feeling it has something to do with the math

Seems like I accidentally solved my own problem, oops. Oh well, thanks for helping I guess?

1 Like

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