How can I force shift lock?

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

86 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.

2 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

2 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

That locks player into third person, but if the mouse is in the center of the screen, the player will be in the center. I want an over the shoulder type camera.

1 Like

Use a localscript to access the humanoid in the player character, then in “CameraOffset” set the value of X to 1 or 2, that will have it on the shoulder instead of centered, sorry I was on a trip for a day and couldn’t answer back.

8 Likes

Thanks, that fixed it for me! It works perfectly now!

2 Likes

Sorry for bumping this old thread. But I didn’t quite get your explanation.

Should I have a script like this inside a local script in StarterPlayerScripts:

plrModule = script.Parent:WaitForChild("PlayerModule")
CameraModule = require(plrModule.CameraModule)



function CameraModule:Update(dt)

self.activeCameraController:SetIsMouseLocked(true)

end

I dont get any errors. But it doesnt do anything either.

3 Likes

Unfortunately this method relied on how the older camera scripts worked, and I think they changed a few things, I made this a while back while I was using it for my own game, but I decided to fish out my old games camera script and slightly document controls, it really was only a few adjustments, but for your use you’ll have to adjust it a bit more to your games liking, you may not be able to go to your ESC menu in studio but it should work in actual gameplay. https://www.roblox.com/library/5173113621/Force-Shiftlock-Forked-Playermodule

(Install into StarterPlayerScripts)

It’s most likely possible to do this with newer player camera scripts, but I have not been experimenting as I haven’t needed to for a while, this can be a temp fix and solution for any forced camera games, feel free to modify and even expand on it if you want, anyone who wants it can have it… enjoy! (Let’s hope one day we get official support for this so we don’t have to fork default roblox scripts :wink: )

9 Likes

Thanks for the long and extensive answer!

Sorry, but, it turns out I tried it in the totally wrong way. I was unaware that the self.activeCameraController:SetIsMouseLocked(true) was supposed to be inside the CameraModule :expressionless:

and when I did what you said (see picture) it worked perfectly.

However, if you could help me with one last thing, that would be great.

So, now, I have the problem that I cannot turn shiftlock on and off. So, when I start the game, shiftlock force is on and will not be disabled.

So, I was wondering, is there any way to implement or to call this function form a local script inside for example, a weapon?

Because, I would like force shiftlock only to be enabled when a weapon is equipped. Or, in general, that I can turn it “On” and “off”.

I am not very experienced with roblox core script modifications and other module scripts in general.

Do you think there is a way to fire that function from a local script turning force shift lock on and off?

Thank you very much for your help so far, and looking forward to your answer.

Sincerely.

Edit 1:

Can I use a remote event to fire that one specific function inside the module script? See picture.

Edit 2:

I used your model that you sent me, it works like a charm. But, if I didn’t misread, is it possible to fire shiftlock on/off here:


Or did I interpret the “conditional” wrong… thanks.

2 Likes