Weapon recoil [HELP]

I want it to keep going up but for some reason when i shoot it does the recoil but it goes to a certain position no matter how many times i shoot it springs up to this limit position and stops i want it to keep going up based on if the player is still shooting.

local function onHeartbeat(self, tool)
	if firing and tool:GetAttribute("Ammo") > 0 then
		if os.clock() - lastShot < 0.1 then return end
		effectsManager.onWeaponFired(tool, player)

		--[[task.delay(0.15, function()
		lastShot = os.clock()

local function applyCameraRecoil(self, deltaTime)
	local recoilAmount = self.recoilSpring.Position * deltaTime * 100  -- Calculate recoil amount

	-- Calculate the change in recoil position since the last frame
	local deltaRecoil = recoilAmount - lastSpringPosition

	-- Update the camera's CFrame by applying the recoil and adding the yOffset
	workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(deltaRecoil, 0, 0)

	-- Update the last spring position to include the recoil amount
	lastSpringPosition = recoilAmount 

1 Like

Do you have a video to show what’s happening? Can’t really figure out what you’re trying to fix only from the script


I got it to go up by changing the damping and speed, but im having trouble figuring out the best values how does damping, and speed affect a spring also how would i apply limits so that the camera does start being weird like at the end of the video when the player is sitting maybe i just need a faster recovery and i should slow down the recovery while shooting im not sure

If I recall correctly how springs work, dampening is how “fast” the forces slow down, and speed is, well, the speed of the spring, just tweak those values until you get a good result.
Based on what I can figure out, to implement a limit, you could probably set a math.clamp() on the recoilAmount, like so: math.clamp(self.recoilSpring.Position * deltaTime * 100, math.rad(40)) (the 40 would be the angle limit)

do i need to multiply the spring position by delta time? would people will lower or higher fps experience problems if i dont

Yes, without being multiplied by the delta time, higher FPS users would have more recoil than those with lower FPS. However you can edit that 100 included in the formula if you need to.

Hey, I know that this thread has been answered but I just wanted to add.

This post has been amazing for me when I was previously implementing recoil, I highly recommend you give it a read on top of the answer that was already given if you want to try it.

It is this post by ChickenBagelz

Should I just not use springs?

Its doing some weird moving up thing idk if its the over the shoulder system but i might just have to give this a try without the springs