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