How can I force shift lock?

For a while now I’ve been meaning to force shift lock for my 3rd person game.Though I did find some ways to do this, they weren’t very efficient because I can’t find any methods to force it and stop forcing it if I(or the player) ever wanted to interact with the menu UI by pressing M.I know it’s possible to force shift lock in your game because I’ve seen it done in a few games before
(Dragon Ball Final Stand by @SnakeWorl for example) , I just don’t know how exactly to go about it or where to start.Is it possible you guys could help me out or at least link me to a good source on this topic?

Please and thank you!

51 Likes

I think u have to go on studio test the game and go at starterplayer.starterplayerscripts.camerascript and there u should find a the shift lock script but if u dont know just paste that instead i found on a reddit post https://www.roblox.com/library/1116734667/Rightclick-to-un-shiftlock-CameraScript

9 Likes

You can use UserInputService.MouseBehaviour.LockCenter to achieve this functionality. UserInputService | Documentation - Roblox Creator Hub

11 Likes

If I recall correctly, LockCenter only affects the mouse, it doesn’t force shift lock.

1 Like

I’m sure he didn’t mean literally forcing shift lock itself, but rather having the same functionality except where it’s toggle-able, as he did say it was for a third person game so I assume he wants the mouse to be locked at the center of the screen so that the player camera can face the direction you move your mouse, kind of like Fortnite.

10 Likes

Can’t you just enable “Modal” on the gui?

1 Like

Modal only frees the mouse in conditions where it’d normally be locked (i.e. zoomed in with a Gui plastered on your screen). It doesn’t force third person nor does it coerce the mouse to stay in the center of the screen.

3 Likes

You could achieve this functionality through editing the PlayerModule so that it is always on shift-lock mode, as opposed to only when the player makes it be. Id start by looking in the “MouseLockController” module or maybe “BaseCamera”, both children of CameraModule.

2 Likes

You will need to use the old camera script. If you put it in, the new control script should still be active. You can find one in free models and edit it your self.

3 Likes

Why the old one? I did it with the new one just fine

2 Likes

Can you publish it as a model?

6 Likes

Inside function CameraModule:Update(dt)

for the CameraModule, you can force shiftlock automatically on

by putting the following code into it

self.activeCameraController:SetIsMouseLocked(true)

If you want rotation you change you can also
GameSettings.RotationType = Enum.RotationType.CameraRelative
or
GameSettings.RotationType = Enum.RotationType.MovementRelative

Using this you can also set up certain conditions for when and if the camera will be forced in situations.

Also you can turn off the toggle players have for shift lock automatically if you go to StarterPlayer.EnableMouseLockOption.

EDIT: alternatively you can used this old forked script.
https://www.roblox.com/library/5173113621/Force-Shiftlock-Forked-Playermodule

94 Likes

This is nice. However, setting the activeCameraController to true does not immediately turn it on when the player joins. They still manually need to toggle shiftlock on and off for them to be stuck in it. I personally have tried settings the mouses X & Y to the middle of the screen when the mouse is moved but you cannot set these values only read from them. I do not know another method of doing this.

3 Likes

Weird, using this method it kept it locked for me unless I forgot something vital, but I shouldn’t have.

2 Likes

I have tried to use this, and it works for the most part. The only part that doesn’t is that it doesn’t do the third person thing. It just locks the mouse and turns the player with the camera, but doesn’t do the third person camera part. Any way I can add that?

1 Like

So you want to force the camera into third person, but not have it follow the camera?

2 Likes

No I want it to be exactly like shiftlock, which has 3 components:

  1. It locks the mouse in center
  2. The character looks towards mouse
  3. The camera is in third person
    Right now, only the first 2 are achieved. How would I do the 3rd one?
3 Likes

you could change maxcamerazoom and mincamerazoom in starterplayer properties

3 Likes

That doesn’t make it third person, it just makes the zoom different.

1 Like

you can set them both to the same value so the player is locked in third person and can’t zoom in-out?

4 Likes