---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


rs.RenderStepped:connect(function ()
	if active then
		if waveScale < 0.5 then
			waveScale = math.min(0.5,waveScale+scaleIncrement)
		end
	else
		if waveScale > 0 then
			waveScale = math.max(0,waveScale-scaleIncrement)
		end
	end
	local abs,cos = math.abs,math.cos
	local camY = c.CoordinateFrame.lookVector.Y
	for joint,def in pairs(RIG) do
		joint.C0 = def.C0 * CFrame.Angles(def.Factor.X*camY,def.Factor.Y*camY,def.Factor.Z*camY)
		joint.C1 = def.C1
	end
	rootJ.C0 = rootJ.C0 * CFrame.new(0,camY,0) -- Painful fix, but the player glides forward and backwards a bit when looking up and down without this.
	local headOffset = CFrame.new()
	if (c.Focus.p-c.CoordinateFrame.p).magnitude < 1 then
		if script.Parent.Parent.PlayerGui.GUI.Asset.Jar.Stamina.Spectation.Running.Value == false then
		c.FieldOfView = 100
		end
		local dist = head.CFrame:toObjectSpace(torso.CFrame).p.magnitude
		headOffset = root.CFrame:toObjectSpace(head.CFrame) - Vector3.new(0,dist - ((1+camY)/8),0.25)
	else
		if script.Parent.Parent.PlayerGui.GUI.Asset.Jar.Stamina.Spectation.Running.Value == false then
		c.FieldOfView = 80
	end
	end
	local t = cos(tick() * (math.pi*2.5))
	local bobble = CFrame.new((t/3)*waveScale,abs(t/5)*waveScale,0) -- Makes the view move side to side. The wave scale is tweened between 0 and 1 depending on if the player is walking or not.
	humanoid.CameraOffset = (headOffset * bobble).p
end)
