Cursor Help - PC and Mobile

Hi there!

I’m trying to create a mobile game where you can shoot other players. I’ve created the majority of the systems however I’ve realised a critical issue in the cursor system.

Essentially the cursor isn’t aiming where the UI is. Now before you say “move the UI”, it works 100% on the PC version of the game with the same code and I’m using a scale position to indicate the centre of the screen (see code below).

You can see the issue for yourself here in this video.

-- Environment: Client
function GetCursorPosition()
	if PlayerGui:FindFirstChild("Cursor") then
		local Position = PlayerGui.Cursor.TextLabel.Position
		local Size = PlayerGui.Cursor.TextLabel.Size
		local X = workspace.CurrentCamera.ViewportSize.X * Position.X.Scale + (Size.X.Offset / 2)
		local Y = workspace.CurrentCamera.ViewportSize.Y * Position.Y.Scale + (Size.Y.Offset / 2)
		local _, TargetPosition = getMouseHit(Tank:GetDescendants())
		return TargetPosition

Is there any reason that the position being returned by the function returns something different on mobile devices than on PC?

Many thanks,
-Tom :slight_smile:

The screen size and shape on the 2 devices may be different, this means that any gui elements positioned using offset will show up in different locations. On the gui, set the anchor point to 0.5,0.5 then the position to 0.5,0,0.5,0 instead of dragging it into position. (If it’s not meant to be centered, play around with the scale properties in the postion)

[EDIT:] I just realised that this wasn’t what you were looking for, I’m still not 100% sure, but if you want it to put the gui where the finger touches the screen, take into account that touching or moving the mover on the bottom left, rotating the camera or clicking other gui elements may interfere with this