I’m trying to constantly get the user’s mouse location on mobile.
The issue is, Mouse.Hit only changes it’s value when UserInputService.TouchTap is fired.
I came to the solution of using Camera:ViewportPointToRay(). But unless the ray intersects with an object no position is returned.
local UserInputService = game:GetService("UserInputService")
local Camera = workspace.CurrentCamera
UserInputService.TouchMoved:Connect(function(Input)
local Position = Input.Position
local ViewportRay = Camera:ViewportPointToRay(Position.X, Position.Y)
if ViewportRay then
local RaycastResult = workspace:Raycast(ViewportRay.Origin, ViewportRay.Direction * 1000)
if RaycastResult then
--3d position is returned
else
--no 3d position is returned
end
end
end)