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