Prevent InputBegan from taking input from a mobile screen touch that is meant for the joystick

Hello, I currently have this tool that I am using which is activated through UserInputService.InputBegan.
The issue I am facing is that when when I check for a screen touch input, it will fire even if the touch occurs in the thumbstick region while using the GameProcessed argument to check. This occurs using only dynamic thumbstick.

I know this is most likely not a bug, but I was wondering how people would get around this kind of issue, since the weapon keeps getting activated when trying to use the joystick.

Here is a simple breakdown of my code:

UIS.InputBegan:Connect(function(input,gP)
	if not gP and input.UserInputType == Enum.UserInputType.Touch then
		-- weapon functions and stuff
	end
end)

If your weapon is a tool, you could use Tool.Activated, it should work correctly without triggering while using mobile joystick

You can also try this in case if your weapon is not a tool:

local function isTouchInJoystickArea(touchPosition)
	local viewportSize = workspace.CurrentCamera.ViewportSize
	local joystickArea = {
		xMin = 0,
		xMax = viewportSize.X * 0.4,
		yMin = viewportSize.Y * 0.3,
		yMax = viewportSize.Y
	}

	return touchPosition.X >= joystickArea.xMin 
		and touchPosition.X <= joystickArea.xMax
		and touchPosition.Y >= joystickArea.yMin 
		and touchPosition.Y <= joystickArea.yMax
end

game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end
	if input.UserInputType == Enum.UserInputType.Touch then
		if isTouchInJoystickArea(input.Position) then return end

		print("Touch")
	end
end)
1 Like

I believe this should work, thank you.
The only issue I have with this is that the actual frame for the joystick takes up a lot of space, and could cause issues if the player wanted to aim somewhere relatively close to that spot. I don’t know how I would solve that issue, and I was wondering what other people had as a work around to this.

Tool.Activated would work but since I also want the player to be able to aim their weapon after activating, which involves dragging their finger across the screen, making this event not fire.

I think you could create a button for mobile so they can shoot, is your game a first person shooter?,