Sway getting stuck before returning to its idle position

im currently experiencing issues with my weapon sway getting stuck for a bit before going to its original position. example:

External Media

this is my code

local spring = require(script:WaitForChild("spring"))

local swaySpring = spring.new()

local maxRot = 10
local dampening = .2

local function ToRad(Number:number)
	return math.rad(
		math.clamp(
			Number*dampening,
			-maxRot,
			maxRot
		)
	)
end

task.spawn(function()

	runService.RenderStepped:Connect(function(dt)

		local delta = -userInputService:GetMouseDelta()

		local pos = Vector3.new(delta.X, delta.Y, 0)

		swaySpring:shove(pos)
		local updatedSway = swaySpring:update(dt)

		viewmodel:PivotTo((workspace.CurrentCamera.CFrame * CFrame.new(Vector3.new(0.5,0,-1.8))) * CFrame.Angles(ToRad(updatedSway.Y), ToRad(updatedSway.X), 0))

	end)	
end)

this happens when i move my camera rapidly and then stop. as you can see, the viewmodel stops for a bit before going back to its position.

3 Likes

i figured it out. the ToRad function was indeed clamping it, but the original value was still getting over the limit, so until it reached a value lower than the max, it was staying at the max. i just clamped the mouse deltas in the same way as the ToRad function and that fixed my issue.

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