function OrbitalCamera.GetCameraToSubjectDistance(o)return o.curDistance end function OrbitalCamera.SetCameraToSubjectDistance(w,o)local A=PlayersService.LocalPlayer if A then w.currentSubjectDistance=Util.Clamp(w.minDistance,w.maxDistance,o)w.currentSubjectDistance=math.max(w.currentSubjectDistance,w.FIRST_PERSON_DISTANCE_THRESHOLD)end w.inFirstPerson=false w:UpdateMouseBehavior()return w.currentSubjectDistance end function OrbitalCamera.CalculateNewLookVector(A,o,w)local e=o or A:GetCameraLookVector()local Q=math.asin(e.y)local l=Util.Clamp(Q-math.rad(MAX_ALLOWED_ELEVATION_DEG),Q-math.rad(MIN_ALLOWED_ELEVATION_DEG),w.y)local W=Vector2.new(w.x,l)local b=CFrame.new(ZERO_VECTOR3,e)local P=((CFrame.Angles(0,-W.x,0)*b)*CFrame.Angles(-W.y,0,0)).lookVector return P end function OrbitalCamera.GetGamepadPan(e,o,w,A)if A.UserInputType==e.activeGamepad and A.KeyCode==Enum.KeyCode.Thumbstick2 then if e.r3ButtonDown or e.l3ButtonDown then if A.Position.Y>THUMBSTICK_DEADZONE then e.gamepadDollySpeedMultiplier=.96 elseif A.Position.Y<-THUMBSTICK_DEADZONE then e.gamepadDollySpeedMultiplier=1.04 else e.gamepadDollySpeedMultiplier=1.0 end else if w==Enum.UserInputState.Cancel then e.gamepadPanningCamera=ZERO_VECTOR2 return end local o=Vector2.new(A.Position.X,-A.Position.Y)if o.magnitude>THUMBSTICK_DEADZONE then e.gamepadPanningCamera=Vector2.new(A.Position.X,-A.Position.Y)else e.gamepadPanningCamera=ZERO_VECTOR2 end end return Enum.ContextActionResult.Sink end return Enum.ContextActionResult.Pass end function OrbitalCamera.DoGamepadZoom(e,o,w,A)if A.UserInputType==e.activeGamepad and(A.KeyCode==Enum.KeyCode.ButtonR3 or A.KeyCode==Enum.KeyCode.ButtonL3)then if w==Enum.UserInputState.Begin then e.r3ButtonDown=A.KeyCode==Enum.KeyCode.ButtonR3 e.l3ButtonDown=A.KeyCode==Enum.KeyCode.ButtonL3 elseif w==Enum.UserInputState.End then if A.KeyCode==Enum.KeyCode.ButtonR3 then e.r3ButtonDown=false elseif A.KeyCode==Enum.KeyCode.ButtonL3 then e.l3ButtonDown=false end if not e.r3ButtonDown and not e.l3ButtonDown then e.gamepadDollySpeedMultiplier=1.0 end end return Enum.ContextActionResult.Sink end return Enum.ContextActionResult.Pass end function OrbitalCamera.BindGamepadInputActions(o)o:BindAction("\079\114\098\105\116\097\108\067\097\109\071\097\109\101\112\097\100\080\097\110",function(w,A,e)return o:GetGamepadPan(w,A,e)end,false,Enum.KeyCode.Thumbstick2)o:BindAction("\079\114\098\105\116\097\108\067\097\109\071\097\109\101\112\097\100\090\111\111\109",function(w,A,e)return o:DoGamepadZoom(w,A,e)end,false,Enum.KeyCode.ButtonR3,Enum.KeyCode.ButtonL3)end
--
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

