Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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)
0
Is this in a LocalScript? User#6546 35 — 7y
0
Is this in a LocalScript? User#6546 35 — 7y
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." TheeDeathCaster 2368 — 7y
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. :) TheeDeathCaster 2368 — 7y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Hello VongolaXII,'

Your answer is right here: https://www.youtube.com/watch?v=7CcKCO7z54o Watch this video! By the way the lines the guy says is different now. The first line he says is in line 197 and the second line is in 247

Ad

Answer this question