Sorry, this response is quite wordy. Looking at tons of words probably isn’t fun.
I mean, it might, but why would you want to use it on mobile? Mouse object should be kept strictly for computer uses. Mobile input, unlike a computer’s mouse, is not constant. Mobile input is dependent on when the user taps on the screen and even then, branches a bit.
In the case that you need a mobile input location, UserInputService.TouchTapInWorld. This is fired when the user taps in the world and not on a Gui, so it’s essentially equivalent to GetMouseLocation as in when the user taps their screen. This is not equivalent to Mouse.Hit though, there is no mobile equivalent for that.
Touch taps, much like the mouse, are done in 2D space. You then need to find a way to turn this 2D input into 3D space. Fortunately, ViewportPointToRay is there again. Between computer and mobile, the only difference you will experience is how you get the 2D position of the user’s input. After that, it’s relatively the same process for both. Get the unit ray, extend it, use a ray method.
Since TouchTapInWorld is an event, you’ll need to connect a function to it. It’ll pass two arguments; the Vector2 space where the user tapped and whether they tapped on a Gui. You’ll need to take the first argument, the Vector2 and feed it into ViewportPointToRay. Notice how it’s the same with GetMouseLocation, which also returns a Vector2 that you can put into that function.
local UserInputService = game:GetService("UserInputService")
UserInputService.TouchTapInWorld:Connect(function (position, processedByUI)
-- Code
end)
ViewportPointToRay generates a unit ray with the properties you pass to it. You can then feed this back into another ray or extend the direction of it. There’s a code sample on the Wiki page itself under TouchTapInWorld, so you can look there and salvage the code as you need.