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