How do I get Mouse.Hit.p on touch devices?

I need to to get the direction from Mouse.Hit.p to HumanoidRootPart.

UserInputService has a lot of events for mobile screens. Best I can think of is keeping track of the last place they had their finger on the screen using multiple different events, and using that position through ScreenPointToRay to figure out where in the 3D world the ray hits.

Doing things this way also comes with the benefit of having more control over ‘Mouse.Hit’. Primarily making a whitelist of objects (and their descendants) you want to be ignored by your mouse.

Mouse.X and Mouse.Y may already keep track of the last position the player had the screen touched. Worth looking into.

Edit: Apparently this just works on mobile. Not sure where your issue came from with it, but I stand by using ScreenPointToRay. Gives so much more control.

2 Likes

Pretty sure it works the same way as on computer?

Mouse.hit.p works on mobile anyway. Works on my game for mobile and I didn’t even consider mobile at all while making it.

Works the same on both platforms, mouse position(X,Y) & mouse.Hit work as well

8 Likes

Thanks everyone for your help.