How to make UserInputService.TouchPan keep track of multiple touches?

I’m at day 2 of trying to make a over the shoulder camera compatibility for mobile, and using Humanoid.MoveDirection, the script can detect if the player is using the thumbstick.

The problem is that I still want the player to be able to move their camera using another finger that’s not operating the thumbstick.

So, I tried adding booleans to detect if the touch is either “firstTouch” or an “extraTouch”.

local touchCamera = UserInputService.TouchPan:Connect(function(touchPositions, totalTranslation, velocity, state, gpe)	
		if state == Enum.UserInputState.Begin then
			if gpe then
				return
			end
			
			if firstTouch == true then
				extraTouch = true
			end
			
			if humanoid.MoveDirection ~= zeroMovement and firstTouch == false then
				firstTouch = true
				print("firstTouched")
			end
		end

		if state == Enum.UserInputState.Change then
		  	if humanoid.MoveDirection ~= zeroMovement and not extraTouch then 
				return 
			end
		    -- Camera Code Omitted for the sake of space --
		end

		if state == Enum.UserInputState.End then
			if extraTouch == true then
				extraTouch = false
				print("extraTouchFalse")
			end
			
			if firstTouch == true and humanoid.MoveDirection == zeroMovement then
				firstTouch = false
				print("firstTouchedFalse")
			end
		end
	end)

The logic is supposed to go:

  1. Player touches screen.
  2. If the player doesn’t have a moveDirection then it means they aren’t using the thumbstick so the camera code will run.
  3. If the player does have a moveDirection then it means they are using the thumbstick, the camera script will not run and it will register the touch as a “firstTouch”.
  4. If the player touches and pans the screen again while “firstTouch” is true then this will turn the “extraTouch” boolean to true, thus the camera code will run.
  5. If the person releases a finger from the screen and the moveDirection is Vector3.new(0,0,0) then that means they aren’t using the thumbstick and they released the finger that set “firstTouch” to true, so “firstTouch” is set to false.
  6. If a finger is released and the humanoid.MoveDirection isn’t (0,0,0) then that means the finger they released was their “extraTouch”, so extraTouch is turned off.

The problem with this is that the .TouchPan is stuck on the “firstTouch” and seemingly doesn’t detect a second touch until you release the “firstTouch”, so “extraTouch” is never set to true, thus the camera code never runs.

I’d show a gif of this, but Roblox Studio doesn’t trigger .TouchPan in its emulator (and I only have 1 mouse).

1 Like

Same issue here, except I have no character.Part of the issue is the TouchPan not working as intended, that is, adding all the fingers to the tables…

Bro, I don’t exactly know how it got fixed, but I switched from UserInputService to ContextActionService and it just works…

For detecting inputs for rotating the camera, I use contextactionservice, and for detecting when the player is pinching their fingers to zoom in/out, I use userinputservice.