Detect when a player taps on mobile/touch device?

I’m currently working on a round based game where player’s golf. Development is coming along very swell, but I noticed an issue while testing on my IPad. I noticed that because I am using UserInputService and Enum.UserInputType.MouseButton1, Player’s are unable to control the GolfBall on mobile devices.

I was wondering if there is some sort of alternative that I can use that will allow for me to detect when a player taps on the screen. I am also using Mouse.Hit and I was wondering if that works on mobile devices.

If you know what Enum I can use that’d be wonderful and if you’re interested in checking out the game, you can do so here GOLF SIMULATOR ⛳🏌️ - Roblox

1 Like

Does Enum.UserInputType.TouchTap not suffice for your use case?

It does but it’s unrecommended to use it because Mouse.Hit doesn’t update live on mobile devices and mobile devices don’t have a mouse. Consider ViewportPointToRay, which constructs a unit ray based off of a 2D position. Here, you can feed the position of the touch via InputObject.Position.

Mouse.Hit is a simplification of the above anyway, except it also extends the unit ray.

7 Likes

Thank you for the recomendation about the ViewportPointToRay, I’ll check it out!

Im getting an error that says TouchTap is not a valid EnumItem. Looks like it’s an event. But that does accomplish my goal so thank you :+1:

Edit: Epic, I got it working nice and well :smiley:

My bad, it’s not TouchTap, it’s simply Touch.

1 Like