Locking mouse to center

Like im sure many other developers have chosen as well, ive elected not to use roblox’s default character system and instead have decided to create my own from scratch. In my efforts to create a first person camera for the character however, i am stuck on how to lock the mouse to the center of the screen. I thought about perhaps just hiding the mouse and using its Delta to move the camera, but for some reason it seems the delta only changes when the mouse’s movement is restricted (ie. locked to center in default roblox first person, right clicking for camera panning, etc) so at the moment i’ve no way of detecting mouse movement unless i lock the mouse to the center of the screen. At the same time however, it seems one can only lock the mouse to the center with LockFirstPerson, which is only usable if you load in roblox’s default character. Does anybody have any suggestions on how i should attack this?

2 Likes

This should be helpful:

3 Likes

Repeatedly setting UserInputService.MouseBehavior to Enum.MouseBehavior.LockCenter will lock the mouse to the center of the screen. In my testing the mouse appeared to glitch a little and disappear for a frame or two but this is the only method I know of. Hopefully, this helps!

The reason one needs to repeat it constantly is because the default roblox scripts are constantly setting it back. I am not loading in the character in whatsoever, and am instead creating a custom character system of my own. As such, none of these default scripts will be present in game and interfering with the mouse lock. The problem here is not that the mouse behavior is constantly being set back, but rather that it simply isnt doing anything at all.

2 Likes

Ok, thanks for explaining. I wasn’t sure that would work. I hope you find a solution.

I dont think this is quite what i am looking for, but thank you though

3 Likes

It seems that it does still seem to revert to MouseBehavior.Default, but only when i right click. when mouseBehavior is constantly set to MouseBehavior.LockCenter it then gives the desired result, but once again this only happens after i right click. I want it to lock in the center immediately, which seems to be the problem now.

1 Like

I tried using InputBegan’s Delta property of the input object, but it looks like that is also (0,0) unless the mouse is locked. I am at a loss here, i dont see why roblox cant just have the delta always set to the mouse movement

1 Like

It looks like MouseBehavior.LockCurrentPosition works instantaniously, unlike its LockCenter counterpart. I dont know why, but im not complaining if this will work for me.

6 Likes