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

function OrbitalCamera:BindGamepadInputActions()
	if FFlagPlayerScriptsBindAtPriority then
		self:BindAction("OrbitalCamGamepadPan", function(name, state, input)
			self:GetGamepadPan(name, state, input)
		end, false, Enum.KeyCode.Thumbstick2)
		self:BindAction("OrbitalCamGamepadZoom", function(name, state, input)
			self:DoGamepadZoom(name, state, input)
		end, false, Enum.KeyCode.ButtonR3, Enum.KeyCode.ButtonL3)
	else
		local ContextActionService = game:GetService("ContextActionService")

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