function OrbitalCamera.GetCameraToSubjectDistance(c)return c.curDistance end function OrbitalCamera.SetCameraToSubjectDistance(A,c)local p=PlayersService.LocalPlayer if p then A.currentSubjectDistance=Util.Clamp(A.minDistance,A.maxDistance,c)A.currentSubjectDistance=math.max(A.currentSubjectDistance,A.FIRST_PERSON_DISTANCE_THRESHOLD)end A.inFirstPerson=false A:UpdateMouseBehavior()return A.currentSubjectDistance end function OrbitalCamera.CalculateNewLookVector(p,c,A)local l=c or p:GetCameraLookVector()local u=math.asin(l.y)local I=Util.Clamp(u-math.rad(MAX_ALLOWED_ELEVATION_DEG),u-math.rad(MIN_ALLOWED_ELEVATION_DEG),A.y)local Z=Vector2.new(A.x,I)local q=CFrame.new(ZERO_VECTOR3,l)local h=((CFrame.Angles(0,-Z.x,0)*q)*CFrame.Angles(-Z.y,0,0)).lookVector return h end function OrbitalCamera.GetGamepadPan(l,c,A,p)if p.UserInputType==l.activeGamepad and p.KeyCode==Enum.KeyCode.Thumbstick2 then if l.r3ButtonDown or l.l3ButtonDown then if p.Position.Y>THUMBSTICK_DEADZONE then l.gamepadDollySpeedMultiplier=.96 elseif p.Position.Y<-THUMBSTICK_DEADZONE then l.gamepadDollySpeedMultiplier=1.04 else l.gamepadDollySpeedMultiplier=1.0 end else if A==Enum.UserInputState.Cancel then l.gamepadPanningCamera=ZERO_VECTOR2 return end local c=Vector2.new(p.Position.X,-p.Position.Y)if c.magnitude>THUMBSTICK_DEADZONE then l.gamepadPanningCamera=Vector2.new(p.Position.X,-p.Position.Y)else l.gamepadPanningCamera=ZERO_VECTOR2 end end return Enum.ContextActionResult.Sink end return Enum.ContextActionResult.Pass end function OrbitalCamera.DoGamepadZoom(l,c,A,p)if p.UserInputType==l.activeGamepad and(p.KeyCode==Enum.KeyCode.ButtonR3 or p.KeyCode==Enum.KeyCode.ButtonL3)then if A==Enum.UserInputState.Begin then l.r3ButtonDown=p.KeyCode==Enum.KeyCode.ButtonR3 l.l3ButtonDown=p.KeyCode==Enum.KeyCode.ButtonL3 elseif A==Enum.UserInputState.End then if p.KeyCode==Enum.KeyCode.ButtonR3 then l.r3ButtonDown=false elseif p.KeyCode==Enum.KeyCode.ButtonL3 then l.l3ButtonDown=false end if not l.r3ButtonDown and not l.l3ButtonDown then l.gamepadDollySpeedMultiplier=1.0 end end return Enum.ContextActionResult.Sink end return Enum.ContextActionResult.Pass end function OrbitalCamera.BindGamepadInputActions(c)c:BindAction("\079\114\098\105\116\097\108\067\097\109\071\097\109\101\112\097\100\080\097\110",function(A,p,l)return c:GetGamepadPan(A,p,l)end,false,Enum.KeyCode.Thumbstick2)c:BindAction("\079\114\098\105\116\097\108\067\097\109\071\097\109\101\112\097\100\090\111\111\109",function(A,p,l)return c:DoGamepadZoom(A,p,l)end,false,Enum.KeyCode.ButtonR3,Enum.KeyCode.ButtonL3)end
--[[ Functions of BaseCamera that are overridden by OrbitalCamera ]]
--
function OrbitalCamera:GetCameraToSubjectDistance()
	return self.curDistance
end

function OrbitalCamera:SetCameraToSubjectDistance(desiredSubjectDistance)
	local player = PlayersService.LocalPlayer
	if player then
		self.currentSubjectDistance = Util.Clamp(self.minDistance, self.maxDistance, desiredSubjectDistance)

		-- OrbitalCamera is not allowed to go into the first-person range
		self.currentSubjectDistance = math.max(self.currentSubjectDistance, self.FIRST_PERSON_DISTANCE_THRESHOLD)
	end
	self.inFirstPerson = false
	self:UpdateMouseBehavior()
	return self.currentSubjectDistance
end

function OrbitalCamera:CalculateNewLookVector(suppliedLookVector, xyRotateVector)
	local currLookVector = suppliedLookVector or self:GetCameraLookVector()
	local currPitchAngle = math.asin(currLookVector.y)
	local yTheta = Util.Clamp(
		currPitchAngle - math.rad(MAX_ALLOWED_ELEVATION_DEG),
		currPitchAngle - math.rad(MIN_ALLOWED_ELEVATION_DEG),
		xyRotateVector.y
	)
	local constrainedRotateInput = Vector2.new(xyRotateVector.x, yTheta)
	local startCFrame = CFrame.new(ZERO_VECTOR3, currLookVector)
	local newLookVector = (CFrame.Angles(0, -constrainedRotateInput.x, 0) * startCFrame * CFrame.Angles(
		-constrainedRotateInput.y,
		0,
		0
	)).lookVector
	return newLookVector
end

function OrbitalCamera:GetGamepadPan(name, state, input)
	if input.UserInputType == self.activeGamepad and input.KeyCode == Enum.KeyCode.Thumbstick2 then
		if self.r3ButtonDown or self.l3ButtonDown then
			-- R3 or L3 Thumbstick is depressed, right stick controls dolly in/out
			if input.Position.Y > THUMBSTICK_DEADZONE then
				self.gamepadDollySpeedMultiplier = 0.96
			elseif input.Position.Y < -THUMBSTICK_DEADZONE then
				self.gamepadDollySpeedMultiplier = 1.04
			else
				self.gamepadDollySpeedMultiplier = 1.00
			end
		else
			if state == Enum.UserInputState.Cancel then
				self.gamepadPanningCamera = ZERO_VECTOR2
				return
			end

			local inputVector = Vector2.new(input.Position.X, -input.Position.Y)
			if inputVector.magnitude > THUMBSTICK_DEADZONE then
				self.gamepadPanningCamera = Vector2.new(input.Position.X, -input.Position.Y)
			else
				self.gamepadPanningCamera = ZERO_VECTOR2
			end
		end
		return Enum.ContextActionResult.Sink
	end
	return Enum.ContextActionResult.Pass
end

function OrbitalCamera:DoGamepadZoom(name, state, input)
	if
		input.UserInputType == self.activeGamepad
		and (input.KeyCode == Enum.KeyCode.ButtonR3 or input.KeyCode == Enum.KeyCode.ButtonL3)
	then
		if state == Enum.UserInputState.Begin then
			self.r3ButtonDown = input.KeyCode == Enum.KeyCode.ButtonR3
			self.l3ButtonDown = input.KeyCode == Enum.KeyCode.ButtonL3
		elseif state == Enum.UserInputState.End then
			if input.KeyCode == Enum.KeyCode.ButtonR3 then
				self.r3ButtonDown = false
			elseif input.KeyCode == Enum.KeyCode.ButtonL3 then
				self.l3ButtonDown = false
			end
			if (not self.r3ButtonDown) and not self.l3ButtonDown then
				self.gamepadDollySpeedMultiplier = 1.00
			end
		end
		return Enum.ContextActionResult.Sink
	end
	return Enum.ContextActionResult.Pass
end

function OrbitalCamera:BindGamepadInputActions()
	self:BindAction("OrbitalCamGamepadPan", function(name, state, input)
		return self:GetGamepadPan(name, state, input)
	end, false, Enum.KeyCode.Thumbstick2)
	self:BindAction("OrbitalCamGamepadZoom", function(name, state, input)
		return self:DoGamepadZoom(name, state, input)
	end, false, Enum.KeyCode.ButtonR3, Enum.KeyCode.ButtonL3)
end
