function OrbitalCamera.GetCameraToSubjectDistance(f)return f.curDistance end function OrbitalCamera.SetCameraToSubjectDistance(G,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 m=PlayersService.LocalPlayer if m then G.currentSubjectDistance=Util.Clamp(G.minDistance,G.maxDistance,f)G.currentSubjectDistance=math.max(G.currentSubjectDistance,G.FIRST_PERSON_DISTANCE_THRESHOLD)end G.inFirstPerson=false G:UpdateMouseBehavior()return G.currentSubjectDistance end function OrbitalCamera.CalculateNewLookVector(m,f,G)local q=f or m:GetCameraLookVector()local r=math.asin(q.y)local c=Util.Clamp(r-math.rad(MAX_ALLOWED_ELEVATION_DEG),r-math.rad(MIN_ALLOWED_ELEVATION_DEG),G.y)local R=Vector2.new(G.x,c)local S=CFrame.new(ZERO_VECTOR3,q)local K=((CFrame.Angles(0,-R.x,0)*S)*CFrame.Angles(-R.y,0,0)).lookVector return K end function OrbitalCamera.GetGamepadPan(q,f,G,m)if m.UserInputType==q.activeGamepad and m.KeyCode==Enum.KeyCode.Thumbstick2 then if q.r3ButtonDown or q.l3ButtonDown then if m.Position.Y>THUMBSTICK_DEADZONE then q.gamepadDollySpeedMultiplier=.96 elseif m.Position.Y<-THUMBSTICK_DEADZONE then q.gamepadDollySpeedMultiplier=1.04 else q.gamepadDollySpeedMultiplier=1.0 end else if G==Enum.UserInputState.Cancel then q.gamepadPanningCamera=ZERO_VECTOR2 return end local f=Vector2.new(m.Position.X,-m.Position.Y)if f.magnitude>THUMBSTICK_DEADZONE then q.gamepadPanningCamera=Vector2.new(m.Position.X,-m.Position.Y)else q.gamepadPanningCamera=ZERO_VECTOR2 end end return Enum.ContextActionResult.Sink end return Enum.ContextActionResult.Pass end function OrbitalCamera.DoGamepadZoom(q,f,G,m)if m.UserInputType==q.activeGamepad and(m.KeyCode==Enum.KeyCode.ButtonR3 or m.KeyCode==Enum.KeyCode.ButtonL3)then if G==Enum.UserInputState.Begin then q.r3ButtonDown=m.KeyCode==Enum.KeyCode.ButtonR3 q.l3ButtonDown=m.KeyCode==Enum.KeyCode.ButtonL3 elseif G==Enum.UserInputState.End then if m.KeyCode==Enum.KeyCode.ButtonR3 then q.r3ButtonDown=false elseif m.KeyCode==Enum.KeyCode.ButtonL3 then q.l3ButtonDown=false end if not q.r3ButtonDown and not q.l3ButtonDown then q.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(G,m,q)return f:GetGamepadPan(G,m,q)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(G,m,q)return f:DoGamepadZoom(G,m,q)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 = 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
