function OrbitalCamera.GetCameraToSubjectDistance(F)return F.curDistance end function OrbitalCamera.SetCameraToSubjectDistance(C,F)print("\079\114\098\105\116\097\108\067\097\109\101\114\097 \083\101\116\067\097\109\101\114\097\084\111\083\117\098\106\101\099\116\068\105\115\116\097\110\099\101 ",F)local R=PlayersService.LocalPlayer if R then C.currentSubjectDistance=math.clamp(F,C.minDistance,C.maxDistance)C.currentSubjectDistance=math.max(C.currentSubjectDistance,C.FIRST_PERSON_DISTANCE_THRESHOLD)end C.inFirstPerson=false C:UpdateMouseBehavior()return C.currentSubjectDistance end function OrbitalCamera.CalculateNewLookVector(R,F,C)local I=F or R:GetCameraLookVector()local S=math.asin(I.y)local y=math.clamp(C.y,S-math.rad(MAX_ALLOWED_ELEVATION_DEG),S-math.rad(MIN_ALLOWED_ELEVATION_DEG))local v=Vector2.new(C.x,y)local q=CFrame.new(ZERO_VECTOR3,I)local j=((CFrame.Angles(0,-v.x,0)*q)*CFrame.Angles(-v.y,0,0)).lookVector return j end function OrbitalCamera.GetGamepadPan(I,F,C,R)if R.UserInputType==I.activeGamepad and R.KeyCode==Enum.KeyCode.Thumbstick2 then if I.r3ButtonDown or I.l3ButtonDown then if R.Position.Y>THUMBSTICK_DEADZONE then I.gamepadDollySpeedMultiplier=.96 elseif R.Position.Y<-THUMBSTICK_DEADZONE then I.gamepadDollySpeedMultiplier=1.04 else I.gamepadDollySpeedMultiplier=1.0 end else if C==Enum.UserInputState.Cancel then I.gamepadPanningCamera=ZERO_VECTOR2 return end local F=Vector2.new(R.Position.X,-R.Position.Y)if F.magnitude>THUMBSTICK_DEADZONE then I.gamepadPanningCamera=Vector2.new(R.Position.X,-R.Position.Y)else I.gamepadPanningCamera=ZERO_VECTOR2 end end return Enum.ContextActionResult.Sink end return Enum.ContextActionResult.Pass end function OrbitalCamera.DoGamepadZoom(I,F,C,R)if R.UserInputType==I.activeGamepad and(R.KeyCode==Enum.KeyCode.ButtonR3 or R.KeyCode==Enum.KeyCode.ButtonL3)then if C==Enum.UserInputState.Begin then I.r3ButtonDown=R.KeyCode==Enum.KeyCode.ButtonR3 I.l3ButtonDown=R.KeyCode==Enum.KeyCode.ButtonL3 elseif C==Enum.UserInputState.End then if R.KeyCode==Enum.KeyCode.ButtonR3 then I.r3ButtonDown=false elseif R.KeyCode==Enum.KeyCode.ButtonL3 then I.l3ButtonDown=false end if not I.r3ButtonDown and not I.l3ButtonDown then I.gamepadDollySpeedMultiplier=1.0 end end return Enum.ContextActionResult.Sink end return Enum.ContextActionResult.Pass end function OrbitalCamera.BindGamepadInputActions(F)F:BindAction("\079\114\098\105\116\097\108\067\097\109\071\097\109\101\112\097\100\080\097\110",function(C,R,I)return F:GetGamepadPan(C,R,I)end,false,Enum.KeyCode.Thumbstick2)F:BindAction("\079\114\098\105\116\097\108\067\097\109\071\097\109\101\112\097\100\090\111\111\109",function(C,R,I)return F:DoGamepadZoom(C,R,I)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)
	print("OrbitalCamera SetCameraToSubjectDistance ", desiredSubjectDistance)
	local player = PlayersService.LocalPlayer
	if player then
		self.currentSubjectDistance = math.clamp(desiredSubjectDistance, self.minDistance, self.maxDistance)

		-- 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 = math.clamp(
		xyRotateVector.y,
		currPitchAngle - math.rad(MAX_ALLOWED_ELEVATION_DEG),
		currPitchAngle - math.rad(MIN_ALLOWED_ELEVATION_DEG)
	)
	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
