Check where a player taps the screen on mobile?

How can I go about checking where the player taps the screen on mobile?

I’d like their automatic weapons to only fire when they are touching the right-side of the screen, not the left (touch pad area).

https://i.gyazo.com/6894857b5801e598bff3285d5ea018a1.mp4

3 Likes

This passes the position(s) as parameter 1, it comes in an array as it supports gestures/multiple touch positions.

1 Like

Thanks, but TouchTap only fires if you quickly tap the screen - it isn’t registered if you hold down your finger on the screen, as you would for automatics.

I’ve tried TouchLongPress too but this fires far too late, and doesn’t fire at all if the player slightly drags their finger.

1 Like

You could try utilizing UserInputService.InputBegan(InputObject). Check if InputObject.UserInputType == Enum.UserInputType.Touch

If it does, you can get the position by doing InputObject.Position, it’s a Vector3 but just use the X,Y values as if it were a Vector2.

1 Like

You should use TouchStarted and TouchEnded. The first returned object is a InputObject which contains touch Position in pixels.

11 Likes

I suppose there’s also those events! :joy:

This works thanks. I’ve simplified this even more and use ‘gameProcessedEvent’ to check if the player is touching a UI (like the touch pad) or not.