function BaseCamera.CalculateNewLookCFrame(r,q)local w=q or r:GetCameraLookVector()local B=math.asin(w.y)local E=math.clamp(r.rotateInput.y,-MAX_Y+B,-MIN_Y+B)local v=Vector2.new(r.rotateInput.x,E)local Z=CFrame.new(ZERO_VECTOR3,w)local x=(CFrame.Angles(0,-v.x,0)*Z)*CFrame.Angles(-v.y,0,0)return x end function BaseCamera.CalculateNewLookVector(r,q)local w=r:CalculateNewLookCFrame(q)return w.lookVector end function BaseCamera.CalculateNewLookVectorVR(q)local r=q:GetSubjectPosition()local w=r-game.Workspace.CurrentCamera.CFrame.p local B=(w*X1_Y0_Z1).unit local E=Vector2.new(q.rotateInput.x,0)local v=CFrame.new(ZERO_VECTOR3,B)local Z=((CFrame.Angles(0,-E.x,0)*v)*CFrame.Angles(-E.y,0,0)).lookVector return(Z*X1_Y0_Z1).unit end function BaseCamera.GetHumanoid(q)local r=player and player.Character if r then local w=q.humanoidCache[player]if w and w.Parent==r then return w else q.humanoidCache[player]=nil local w=r:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")if w then q.humanoidCache[player]=w end return w end end return nil end function BaseCamera.GetHumanoidPartToFollow(w,q,r)if r==Enum.HumanoidStateType.Dead then local r=q.Parent if r then return r:FindFirstChild("\072\101\097\100")or q.Torso else return q.Torso end else return q.Torso end end function BaseCamera.UpdateGamepad(q)local r=q.gamepadPanningCamera if r and(q.hasGameLoaded or not VRService.VREnabled)then r=Util.GamepadLinearToCurve(r)local w=tick()if r.X~=0 or r.Y~=0 then q.userPanningTheCamera=true elseif r==ZERO_VECTOR2 then q.userPanningTheCamera=false q.lastThumbstickRotate=nil if q.lastThumbstickPos==ZERO_VECTOR2 then q.currentSpeed=0 end end local B=0 if q.lastThumbstickRotate then if VRService.VREnabled then q.currentSpeed=q.vrMaxSpeed else local B=(w-q.lastThumbstickRotate)*10 q.currentSpeed=q.currentSpeed+q.maxSpeed*((B*B)/q.numOfSeconds)if q.currentSpeed>q.maxSpeed then q.currentSpeed=q.maxSpeed end if q.lastVelocity then local B=(r-q.lastThumbstickPos)/(w-q.lastThumbstickRotate)local E=(B-q.lastVelocity).magnitude if E>12 then q.currentSpeed=q.currentSpeed*(20/E)if q.currentSpeed>q.maxSpeed then q.currentSpeed=q.maxSpeed end end end end B=UserGameSettings.GamepadCameraSensitivity*q.currentSpeed q.lastVelocity=(r-q.lastThumbstickPos)/(w-q.lastThumbstickRotate)end q.lastThumbstickPos=r q.lastThumbstickRotate=w return Vector2.new(r.X*B,((r.Y*B)*q.ySensitivity)*UserGameSettings:GetCameraYInvertValue())end return ZERO_VECTOR2 end
-- Replacements for RootCamera:RotateCamera() which did not actually rotate the camera
-- suppliedLookVector is not normally passed in, it's used only by Watch camera
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
