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