How to make recoil increase the more you shoot?

Im making a gun system and I want to make realistic recoil for automatic weapons, right now it only springs the camera to one position for the duration that you are firing. I want to make it so that your recoil will increase the longer you fire but, make it so there is a limit to how much it increase by. Here is my current code:

local function onRenderStepped(deltaTime: number)
	if shooting then
		RecoilSpring:shove(Vector3.new(recoil, 0, 0.05) * deltaTime * 60)
		task.delay(0.1, function()
			RecoilSpring:shove(Vector3.new(-recoil, -0, -0.05) * deltaTime * 60)
		end)
	end
	local recoil = RecoilSpring:update(deltaTime)
	camera.CFrame = camera.CFrame * CFrame.Angles(recoil.X, recoil.Y, recoil.Z)
end

Fixed. I added a “fired” variable that gets set to true when the gun fires and get’s set to false momentarily. I used this instead of my “shooting” variable which was set to true constantly while you were holding down.

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