Center Cursor on Mobile

Hi! Does anyone know how to make the Mouse go to the center while clicking on mobile?


^ On PC it looks fine and since the mouse is locked it will always go to the center

^ However, on mobile the thing is different, since mobile doesn’t detect LockFirstPerson it will reject it, and replace it with Classic, the thing I want to achieve is that the mouse stays in the center of the screen and when shooting it will make the bullet go straight to the center.

1 Like

Create an outer frame, with the size UDim2.fromScale(1, 1), and Position UDim2.fromScale(0.5, 0.5), then your cursor in that frame.

How would I put the cursor in the frame?
(Not the ‘cursor image’)

You can’t, for mobile just lock the mouse, and do the frame thing I previously said.

Edit: or I believe if you only lock the mouse, it will be automatically set to the center on mobile (you are running the emulator not mobile).


This is the result I get, the Cursor is positioned right, but shooting is odd, maybe is it because of mouse.Hit.Position

If you aren’t locking the mouse, I believe it would be better to raycast from the middle of the screen, instead of using Mouse.

Btw did the answer I gave solve the cursor problem?.

How would I do the raycast in the middle of the screen?

(The answer to that question is Yes, the emulator was the problem)

If my answer solved your original problem, please select it as the answer.

local camera = workspace.CurrentCamera
local cameraCF = camera.CFrame

local length = 1000
local params = RaycastParams.new()

local raycastResult = workspace:Raycast(cameraCF.Position, cameraCF.LookVector * length, params)

Code sample originated here:

2 Likes

How would I make it a server script? Since CurrentCamera doesn’t work globally

Why not just send the camera cframe from client side with a remote event?

Yup, I totally forgot about that

Alright so is that all?
(remember to select a solution, so people don’t try to answer to an already solved problem!)

I’m testing it right now, I won’t forget about selecting solution

I’m not talking about the code sample, if my answer solved your original problem, select it as the answer, because that’s what people will come to answer, not the raycasting problem.

So is it the right one I just marked as answer?

Probably this one since following these specific instructions, solved your problem didn’t it?

But which ever one you want, because I guess they all sort of helped solve your problem lol

1 Like