Gun sway? Maybe springs? Help please!

hey so i have this little, viewport model system for my guns! Im having trouble adding gun sway tho… animations just dont cut it. I hear people are using springs but cant find anything helpful to me about it. Any help?

This function is running for ever renderstepped:

function WeaponAlignADS()
	if Player.Character.Humanoid.Health == 0 then
		if Camera:FindFirstChild("VM") ~= nil then
			Camera.VM:Destroy()
		end
	end

	if Camera:FindFirstChild("VM") ~= nil and aiming == false then
		
		UIS.MouseIconEnabled = false
		Camera.VM:SetPrimaryPartCFrame(Camera.CFrame * CFrame.new(tool.vX.Value,tool.vY.Value,tool.vZ.Value) * CFrame.Angles(0, 0, 0))
		
	end
end

use a lerping function to ease the positioning, maybe you can find an elastic lerp formula that may help

How would i implement the lerping formula into that code?

function WeaponAlignADS()
	if Player.Character.Humanoid.Health == 0 then
		if Camera:FindFirstChild("VM") ~= nil then
			Camera.VM:Destroy()
		end
	end

	if Camera:FindFirstChild("VM") ~= nil and aiming == false then
		
		UIS.MouseIconEnabled = false
		local cf = Camera.CFrame * CFrame.new(tool.vX.Value,tool.vY.Value,tool.vZ.Value) * CFrame.Angles(0, 0, 0)
		Camera.VM:SetPrimaryPartCFrame(Camera.VM:GetPrimaryPartCFrame():Lerp(cf,1/60))
		
	end
end

Please fix typos as I wrote this on mobile. :p

1 Like

Thanks man! Lerp seems to work, however the viewmodel is sliding all aroudn the baseplate…

As I mentioned that I did wrote this on mobile and I am unable to fix it right now. Sorry.