--------------------[ CAMERA STEADYING FUNCTIONS ]------------------------------------


function steadyCamera()
	scopeSteady.Text = "Steadying..."
	scopeSteady.TextColor3 = Color3.new(1, 1, 0)
	camSteady = true
	local originalSway = camSway
	local Increment = 1.5 / 0.6
	local X = 0
	while true do
		RS.RenderStepped:wait()
		local newX = X + Increment
		X = (newX > 90 and 90 or newX)
		if (not steadyKeyPressed) then break end
		camSway = numLerp(originalSway, 0, Sine(X))
		if X == 90 then break end
	end
	while steadyKeyPressed and Aimed do
		if currentSteadyTime > 0 then
			local NewSteadyTime = currentSteadyTime - 1
			currentSteadyTime = (NewSteadyTime < 0 and 0 or NewSteadyTime)
			camSway = 0
		elseif currentSteadyTime == 0 then
			break
		end
		RS.RenderStepped:wait()
	end
	camSteady = false
	spawn(function()
		local Increment = 1.5 / 0.25
		local X = 0
		while true do
			RS.RenderStepped:wait()
			local newX = X + Increment
			X = (newX > 90 and 90 or newX)
			if camSteady then break end
			camSway = numLerp(0, S.scopeSettings.camSwayOnBreath, 1 - COS(RAD(X)))
			if X == 90 then break end
		end
		Increment = 1.5 / S.scopeSettings.breathTime
		X = 0
		while true do
			RS.RenderStepped:wait()
			local newX = X + Increment
			X = (newX > 90 and 90 or newX)
			if camSteady then break end
			camSway = numLerp(S.scopeSettings.camSwayOnBreath, 1, Sine(X))
			if X == 90 then break end
		end
		--[[for X = 0, 90, 1.5 / 0.2 do
			local Alpha = 1 - COS(RAD(X))--math.log10(X) / math.log10(90)
			camSway = numLerp(0, 3, Alpha)
			RS.RenderStepped:wait()
		end]]
		--[[for X = 0, 90, 1.5 / S.scopeSettings.steadyTime do
			if camSteady then break end
			local Alpha = SIN(RAD(X))
			camSway = numLerp(3, 1, Alpha)
			RS.RenderStepped:wait()
		end]]
	end)
	retakeBreath()
end

function retakeBreath()
	scopeSteady.Text = "Re-taking Breath"
	scopeSteady.TextColor3 = Color3.new(1, 0, 0)
	takingBreath = true
	local Increment = S.scopeSettings.steadyTime / S.scopeSettings.breathTime
	while takingBreath do
		if currentSteadyTime < maxSteadyTime then
			local newSteadyTime = currentSteadyTime + Increment
			currentSteadyTime = (newSteadyTime > maxSteadyTime and maxSteadyTime or newSteadyTime)
		elseif currentSteadyTime >= maxSteadyTime then
			break
		end
		RS.RenderStepped:wait()
	end
	if takingBreath then
		scopeSteady.Text = "Hold "..convertKey(S.Keys.scopeSteady).." to Steady"
		scopeSteady.TextColor3 = Color3.new(1, 1, 0)
		takingBreath = false
	end
end
