function BaseCamera.CalculateNewLookCFrame(C,m)local r=m or C:GetCameraLookVector()local v=math.asin(r.y)local Z=Util.Clamp(-MAX_Y+v,-MIN_Y+v,C.rotateInput.y)local G=Vector2.new(C.rotateInput.x,Z)local z=CFrame.new(ZERO_VECTOR3,r)local Y=(CFrame.Angles(0,-G.x,0)*z)*CFrame.Angles(-G.y,0,0)return Y end function BaseCamera.CalculateNewLookVector(C,m)local r=C:CalculateNewLookCFrame(m)return r.lookVector end function BaseCamera.CalculateNewLookVectorVR(m)local C=m:GetSubjectPosition()local r=C-game.Workspace.CurrentCamera.CFrame.p local v=(r*X1_Y0_Z1).unit local Z=Vector2.new(m.rotateInput.x,0)local G=CFrame.new(ZERO_VECTOR3,v)local z=((CFrame.Angles(0,-Z.x,0)*G)*CFrame.Angles(-Z.y,0,0)).lookVector return(z*X1_Y0_Z1).unit end function BaseCamera.GetHumanoid(m)local C=Players.LocalPlayer local r=C and C.Character if r then local v=m.humanoidCache[C]if v and v.Parent==r then return v else m.humanoidCache[C]=nil local v=r:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")if v then m.humanoidCache[C]=v end return v end end return nil end function BaseCamera.GetHumanoidPartToFollow(r,m,C)if C==Enum.HumanoidStateType.Dead then local C=m.Parent if C then return C:FindFirstChild("\072\101\097\100")or m.Torso else return m.Torso end else return m.Torso end end function BaseCamera.UpdateGamepad(m)local C=m.gamepadPanningCamera if C and(m.hasGameLoaded or not VRService.VREnabled)then C=Util.GamepadLinearToCurve(C)local r=tick()if C.X~=0 or C.Y~=0 then m.userPanningTheCamera=true elseif C==ZERO_VECTOR2 then m.lastThumbstickRotate=nil if m.lastThumbstickPos==ZERO_VECTOR2 then m.currentSpeed=0 end end local v=0 if m.lastThumbstickRotate then if VRService.VREnabled then m.currentSpeed=m.vrMaxSpeed else local v=(r-m.lastThumbstickRotate)*10 m.currentSpeed=m.currentSpeed+m.maxSpeed*((v*v)/m.numOfSeconds)if m.currentSpeed>m.maxSpeed then m.currentSpeed=m.maxSpeed end if m.lastVelocity then local v=(C-m.lastThumbstickPos)/(r-m.lastThumbstickRotate)local Z=(v-m.lastVelocity).magnitude if Z>12 then m.currentSpeed=m.currentSpeed*(20/Z)if m.currentSpeed>m.maxSpeed then m.currentSpeed=m.maxSpeed end end end end v=UserGameSettings.GamepadCameraSensitivity*m.currentSpeed m.lastVelocity=(C-m.lastThumbstickPos)/(r-m.lastThumbstickRotate)end m.lastThumbstickPos=C m.lastThumbstickRotate=r return Vector2.new(C.X*v,((C.Y*v)*m.ySensitivity)*UserGameSettings:GetCameraYInvertValue())end return ZERO_VECTOR2 end

function BaseCamera:CalculateNewLookCFrame(suppliedLookVector)
	local currLookVector = suppliedLookVector or self:GetCameraLookVector()
	local currPitchAngle = math.asin(currLookVector.y)
	local yTheta = Util.Clamp(-MAX_Y + currPitchAngle, -MIN_Y + currPitchAngle, self.rotateInput.y)
	local constrainedRotateInput = Vector2.new(self.rotateInput.x, yTheta)
	local startCFrame = CFrame.new(ZERO_VECTOR3, currLookVector)
	local newLookCFrame = CFrame.Angles(0, -constrainedRotateInput.x, 0) * startCFrame * CFrame.Angles(-constrainedRotateInput.y,0,0)
	return newLookCFrame
end
function BaseCamera:CalculateNewLookVector(suppliedLookVector)
	local newLookCFrame = self:CalculateNewLookCFrame(suppliedLookVector)
	return newLookCFrame.lookVector
end

function BaseCamera:CalculateNewLookVectorVR()
	local subjectPosition = self:GetSubjectPosition()
	local vecToSubject = (subjectPosition - game.Workspace.CurrentCamera.CFrame.p)
	local currLookVector = (vecToSubject * X1_Y0_Z1).unit
	local vrRotateInput = Vector2.new(self.rotateInput.x, 0)
	local startCFrame = CFrame.new(ZERO_VECTOR3, currLookVector)
	local yawRotatedVector = (CFrame.Angles(0, -vrRotateInput.x, 0) * startCFrame * CFrame.Angles(-vrRotateInput.y,0,0)).lookVector
	return (yawRotatedVector * X1_Y0_Z1).unit
end

function BaseCamera:GetHumanoid()
	local player = Players.LocalPlayer
	local character = player and player.Character
	if character then
		local resultHumanoid = self.humanoidCache[player]
		if resultHumanoid and resultHumanoid.Parent == character then
			return resultHumanoid
		else
			self.humanoidCache[player] = nil -- Bust Old Cache
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			if humanoid then
				self.humanoidCache[player] = humanoid
			end
			return humanoid
		end
	end
	return nil
end

function BaseCamera:GetHumanoidPartToFollow(humanoid, humanoidStateType)
	if humanoidStateType == Enum.HumanoidStateType.Dead then
		local character = humanoid.Parent
		if character then
			return character:FindFirstChild("Head") or humanoid.Torso
		else
			return humanoid.Torso
		end
	else
		return humanoid.Torso
	end
end

function BaseCamera:UpdateGamepad()
	local gamepadPan = self.gamepadPanningCamera
	if gamepadPan and (self.hasGameLoaded or not VRService.VREnabled) then
		gamepadPan = Util.GamepadLinearToCurve(gamepadPan)
		local currentTime = tick()
		if gamepadPan.X ~= 0 or gamepadPan.Y ~= 0 then
			self.userPanningTheCamera = true
		elseif gamepadPan == ZERO_VECTOR2 then
			self.lastThumbstickRotate = nil
			if self.lastThumbstickPos == ZERO_VECTOR2 then
				self.currentSpeed = 0
			end
		end

		local finalConstant = 0

		if self.lastThumbstickRotate then
			if VRService.VREnabled then
				self.currentSpeed = self.vrMaxSpeed
			else
				local elapsedTime = (currentTime - self.lastThumbstickRotate) * 10
				self.currentSpeed = self.currentSpeed + (self.maxSpeed * ((elapsedTime*elapsedTime)/self.numOfSeconds))

				if self.currentSpeed > self.maxSpeed then self.currentSpeed = self.maxSpeed end

				if self.lastVelocity then
					local velocity = (gamepadPan - self.lastThumbstickPos)/(currentTime - self.lastThumbstickRotate)
					local velocityDeltaMag = (velocity - self.lastVelocity).magnitude

					if velocityDeltaMag > 12 then
						self.currentSpeed = self.currentSpeed * (20/velocityDeltaMag)
						if self.currentSpeed > self.maxSpeed then self.currentSpeed = self.maxSpeed end
					end
				end
			end

			finalConstant = UserGameSettings.GamepadCameraSensitivity * self.currentSpeed
			self.lastVelocity = (gamepadPan - self.lastThumbstickPos)/(currentTime - self.lastThumbstickRotate)
		end

		self.lastThumbstickPos = gamepadPan
		self.lastThumbstickRotate = currentTime

		return Vector2.new( gamepadPan.X * finalConstant, gamepadPan.Y * finalConstant * self.ySensitivity * UserGameSettings:GetCameraYInvertValue())
	end

	return ZERO_VECTOR2
end
