function BaseCamera.CalculateNewLookCFrame(K,t)local s=t or K:GetCameraLookVector()local o=math.asin(s.y)local a=math.clamp(K.rotateInput.y,-MAX_Y+o,-MIN_Y+o)local j=Vector2.new(K.rotateInput.x,a)local q=CFrame.new(ZERO_VECTOR3,s)local p=(CFrame.Angles(0,-j.x,0)*q)*CFrame.Angles(-j.y,0,0)return p end function BaseCamera.CalculateNewLookVector(K,t)local s=K:CalculateNewLookCFrame(t)return s.lookVector end function BaseCamera.CalculateNewLookVectorVR(t)local K=t:GetSubjectPosition()local s=K-game.Workspace.CurrentCamera.CFrame.p local o=(s*X1_Y0_Z1).unit local a=Vector2.new(t.rotateInput.x,0)local j=CFrame.new(ZERO_VECTOR3,o)local q=((CFrame.Angles(0,-a.x,0)*j)*CFrame.Angles(-a.y,0,0)).lookVector return(q*X1_Y0_Z1).unit end function BaseCamera.GetHumanoid(t)local K=player and player.Character if K then local s=t.humanoidCache[player]if s and s.Parent==K then return s else t.humanoidCache[player]=nil local s=K:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")if s then t.humanoidCache[player]=s end return s end end return nil end function BaseCamera.GetHumanoidPartToFollow(s,t,K)if K==Enum.HumanoidStateType.Dead then local K=t.Parent if K then return K:FindFirstChild("\072\101\097\100")or t.Torso else return t.Torso end else return t.Torso end end function BaseCamera.UpdateGamepad(t)local K=t.gamepadPanningCamera if K and(t.hasGameLoaded or not VRService.VREnabled)then K=Util.GamepadLinearToCurve(K)local s=tick()if K.X~=0 or K.Y~=0 then t.userPanningTheCamera=true elseif K==ZERO_VECTOR2 then t.userPanningTheCamera=false t.lastThumbstickRotate=nil if t.lastThumbstickPos==ZERO_VECTOR2 then t.currentSpeed=0 end end local o=0 if t.lastThumbstickRotate then if VRService.VREnabled then t.currentSpeed=t.vrMaxSpeed else local o=(s-t.lastThumbstickRotate)*10 t.currentSpeed=t.currentSpeed+t.maxSpeed*((o*o)/t.numOfSeconds)if t.currentSpeed>t.maxSpeed then t.currentSpeed=t.maxSpeed end if t.lastVelocity then local o=(K-t.lastThumbstickPos)/(s-t.lastThumbstickRotate)local a=(o-t.lastVelocity).magnitude if a>12 then t.currentSpeed=t.currentSpeed*(20/a)if t.currentSpeed>t.maxSpeed then t.currentSpeed=t.maxSpeed end end end end o=UserGameSettings.GamepadCameraSensitivity*t.currentSpeed t.lastVelocity=(K-t.lastThumbstickPos)/(s-t.lastThumbstickRotate)end t.lastThumbstickPos=K t.lastThumbstickRotate=s return Vector2.new(K.X*o,((K.Y*o)*t.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 = math.clamp(self.rotateInput.y, -MAX_Y + currPitchAngle, -MIN_Y + currPitchAngle)
	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 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.userPanningTheCamera = false
			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
