Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I lock the player's mouse to the center of the screen?

I'm trying to make a third-person shooter type game of sorts, and I'm running into a couple of problems. One such problem is that I want to lock the player's cursor to the center of the screen like how it's like in a first person shooter.

I have tried using the LockCenter Enum of MouseBehavior shown in ROBLOX Wiki (code below, but its just the example they gave), but my cursor still moves around freely.

local UserInputService = game:GetService("UserInputService")
 
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
UserInputService.InputChanged:connect(function(inputObject)
	if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
		print("delta is (" .. tostring(inputObject.Delta.x) .. ", " ..  tostring(inputObject.Delta.y) .. ")")
	end
end)

4 comments

0

Is this in a LocalScript?

0

Is this in a LocalScript?

0

The code appears to only be used to return the position of the mouse; I say this b/c of line 6, of how it uses "Delta.x" & "Delta.y."

0

Also, you could set the player's CameraMode to "FirstPersonLock," as that'll force the player to have first person, like in FPS games, and the cursor will stay in the middle of the screen; however, to add, I recommend not doing "CameraMode = 'LFP' ," and instead use "Enum.CameraMode.LFP," as that's much better. :)

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.