How would I make players face their 'mouse' on mobile devices?

local touchPos
uis.TouchMoved:Connect(function(touch, gp)
    if gp then return end

	touchPos = touch.Position
	print(touchPos) -- prints even when you're moving joystick
end)

game:GetService("RunService").RenderStepped:Connect(function()
    if not userIsOnMobile() then
        gyro.CFrame = CFrame.new(pp.Position, Vector3.new(mouse.Hit.p.X, pp.Position.Y, mouse.Hit.p.Z - 14.4))
    else
        -- ??
    end
end)

When I use the same line of code for mobile users as I use for desktop users, the player doesn’t know which direction to face when they are moving as you can see by the video. I was thinking of using the TouchMoved event of UserInputService and sending a ray to the map to get the Vector3, however I quickly realised that gameProcessedEvent doesn’t include the virtual joystick, so I would have the same problem.

The only way I can think of that might make this work is creating my own movement system for mobile users using guis, but I have a feeling that would make no difference and I’d like to know if there’s a simpler option.

4 Likes

Try including it inside the UIS event, then it can differentiate GameProcessedEvents.

You may want to also consider setting the ‘TargetFilter’ property on the mouse, to provide a bit more of a predictable input.
If there are walls in the way you may have issue pointing exactly where you place your finger.

(May also be worth looking into the Viewport and Screen functions of the camera).


function Point(io,gp)
    if gp then return end
    if not userIsOnMobile() then
        gyro.CFrame = CFrame.new(pp.Position, Vector3.new(mouse.Hit.p.X, pp.Position.Y, mouse.Hit.p.Z - 14.4))
    end
end

uis.InputBegin:Connect(Point)
uis.InputChanged:Connect(Point)
uis.InputEnded:Connect(Point) -- might not need this one.

Sorry, I don’t understand how that would ignore the joystick inputs.
I have an invisible part at the camera, so there’s no need for TargetFilter.
I’ve also edited the code I provided. The if statement was meant to be in a RenderStepped loop.

Game Processed Events identifies any input using Roblox’s stuff, like the joysticks, chat.

So, like you did with: if gp then return end to break out of the function, you can do the same when pointing.

It will also be a little more efficient, as you’re only pointing the character when you touch the screen.

Oh I see what you meant. I’ll try it and see if it works but I don’t think it does identify joystick movement.

After trying it out it didn’t seem to fix anything and gave the same result.