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

