Get position of touch not on the mobile thumbstick

I want to handle the case of multi-touch input on a mobile device. For this to work I need the position of a touch that isn’t interacting with the mobile thumbstick.

So let’s say your left thumb is dragging the thumbstick, and you tap your right finger on the screen. I need the location of the right finger. Left thumb can be ignored.

Afaik there’s no way to check if a touch object is interacting with the mobile thumbstick or not.

For that you can use TouchTapInWorld, it gives you the position on screen of where you tap:

That unfortunately doesn’t separate thumbstick interactions from the non-thumbstick interactions.

Also I don’t need 3d position. 2d gui pixels is fine.

TouchTap should give you the exact position of where you tapped, dragging the thumbstick wont count as tapping so that action shouldn’t trigged the function.
If you simply don’t want to be able to tap in the thumbstick area you can check if the position of the tap is within it.
If you don’t want to be able to move if you are interacting with a ui over the thumbstick area you can add an invisible button behind the gui which will stop input from passing through it.

Ok I see but I want the actual drag to be detected ideally.

It’s a radial menu that pops up at the center of the screen. I want the user to be able to use that while moving.

The first thing that comes to mind is to save the touch input that started on the radial menu and only listen to changes of that input:

local UIS = game:GetService("UserInputService")

local frame = script.Parent.Frame --your radial menu
local activeInput

local function isWithinMenu(touchPos) 
	local absPos = frame.AbsolutePosition
	local absSize = frame.AbsoluteSize
	
	--input.Position returns a Vector3 so we have to convert it to a Vector2
	local pos = Vector2.new(touchPos.X, touchPos.Y)
	local center = absPos + (absSize / 2)
	local distance = (pos - center).Magnitude
	
	--return whether or not the touch started within the radial menu
	return distance <= (absSize.X / 2)
end

UIS.TouchStarted:Connect(function(input)
	if isWithinMenu(input.Position) then
		activeInput = input
	end
end)

UIS.TouchEnded:Connect(function(input)
	if input == activeInput then
		activeInput = nil
	end
end)

UIS.InputChanged:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Touch then
		if input ~= activeInput then return end
		print(input.Position)
	end
end)

Im not sure if this is the best way to do this, but it should work.
Make sure to connect these only when radial menu is visible and disconnect them when you finish using it.

I thought of that.
But the issue with that is that there’s no guarantee the user actually touches into the radial menu for the input to register. They’re allowed to tap anywhere on the screen and it’ll use the angle to select an element in the menu.

What I’m really looking for is a way to detect if a touch is interacting with the mobile thumbstick. If I know that, I can just assume the first other touch is for interacting with the radial menu. Afaik there’s no way to actually do this.

If you start listening to the input only when radial menu is opened, you can ignore the input that started moving of the thumbstick which will allow you to keep moving while you select an option in the radial menu.
Issue is if you want to allow player to start moving while the radial menu is open. In this case a big problem is that even if you detect the thumbstick interactions, player can still not interact with the radial menu without rotating their camera. To fix this you would have to obscure controls with the ui (by simply covering whole screen with an invisible active frame) so all interactions only affect the radial menu (which would be the standard way of doing it).

There might be a way to detect which input is interacting with the thumbstick by either forking or somehow connecting to the PlayerModuleControlModuleTouchThumbstick. But as I previously stated, just detecting thumbstick interaction won’t help with the camera rotation issue.

So my recommendation would be to just have it so when radial menu is open, player can’t interact with other controls for simplicity.

1 Like