How to make Shift Lock not rotate the player character [Tutorial] [Easy]

As all of you may know, enabling shift-lock causes the player’s mouse to lock to the center of the screen, as well as make the character point towards the mouse’s direction. This is caused by the Player’s “PlayerModule” module-scripts, which are added by default on every experience in Roblox.

Documentation about these modules is scarce, and understanding what to look for and where can be a challenging task for any developer who was never dealt with these before.

These modules can be found by quickly running a playtest and searching in your player’s PlayerScripts Folder.
image
(Figure 1. Location of PlayerModule)

You must copy this modulescript to your clipboard, exit the playtest, and paste it to StarterPlayer>StarterPlayerScripts in order to make edits to it that will reflect on your final game.
image
(Figure 2. PlayerModule pasted to StarterPlayerScripts)

Now, to remove the shift lock rotation we must edit a module within “CameraModule”, named “CameraUtils”, as this module houses a function that overrides the behavior of the player’s rotation.

The function to look for is the following:

	function CameraUtils.setRotationTypeOverride(value: Enum.RotationType)
		if UserGameSettings.RotationType ~= lastRotationTypeOverride then
			savedRotationType = UserGameSettings.RotationType
		end

		UserGameSettings.RotationType = value
		lastRotationTypeOverride = value
	end

As the time of writing this it can be found around line ~312, and we must only change the last two lines of code to the following:

Replace the “value” variable for Enum.RotationType.MovementRelative. And that should be it!
(Keep in mind that as a consequence of editing this function, first person will also no longer have rotation)

Now, If you also want the mouse/camera to be centered on the character, and not offset to the right, you can change the offset in a different module within CameraModule, called “MouseLockController”
image
Here you must modify the “CameraOffset” Vector3Value, or add one if you can’t find it.
(if you do add a vector3value object it must be named precisely "CameraOffset".)


EDIT:

To have finer control over when to enable shiftlock rotation, rather than permanently disabling them follow these instructions instead:


And now for some questions that I feel should be answered:

Why have I decided to make a tutorial about this topic?
As I had briefly mentioned at the start, documentation on these modules is scarce. Most of the things you can find are forum posts themselves of people looking-into and finding solutions to specific problems they have because of changes they want to make. And for entry level developers it can be an extremely daunting task to look through these modules, which include more-complicated knowledge about OOP and metatables.

But most of all, It’s mainly because I did not know how to do this myself and had to spend a handful of hours searching for answers. And the answer I did find was in reference to a PlayerScript from a previous update, in which I could not find any of the things they mentioned because the updated version of this module has really big changes :disappointed_relieved:. Yet it was still really insightful as it provided much needed clarity as to specifically what controls the rotating behavior.

This has lead me to decide to upload my module aswell, so future readers can compare the code to their current playermodule, and see if this tutorial is still relevant.
PlayerModule.rbxm (128.5 KB)

25 Likes

Still shiftlock can see through thin wall?

I may not be understanding this post, but isn’t the entire purpose of shift-lock that it rotates the character? Why would you want to remove that?

6 Likes

Yeah, you can still see through walls with this. That is beyond the scope of this tutorial

Many third-person games outside of roblox don’t lock your character to the direction you’re looking with your camera at unless you’re aiming, and this can help replicate that effect. Some roblox combat games do this aswell to my knowledge, and I’ve seen this question be asked recently:

3 Likes

There is also a way that easy to disable character rotating while Shift Locking. Let’s look out for “BaseCamera”, which is a child of “CameraModule”.

Around code lines 628 to 648, there is a function called “UpdateMouseBehavior”, which will both lock the mouse and change camera rotation type with other module firings.
2022-07-23

We can easily edit the statement by adding one conditional that changes camera rotation type to Enum.RotationType.CameraRelative for the first person only.

So the code can be changed like this, above the circled part:

if self.inFirstPerson or self.inMouseLockedMode then
	if self.inFirstPerson then
		CameraUtils.setRotationTypeOverride(Enum.RotationType.CameraRelative)
	end
	CameraUtils.setMouseBehaviorOverride(Enum.MouseBehavior.LockCenter)
else
	CameraUtils.restoreRotationType()
	CameraUtils.restoreMouseBehavior()
end

In this case, it will only be changing the camera rotation type for the first person now.

After all, if you edit “BaseCamera” in this way, you have no need to change anything like “CameraUtils” and things will go well.

I was working on a game mechanics that will still need to change my camera rotation type to Enum.RotationType.CameraRelative sometimes, and when I use the method with this topic, I can never change my camera rotation type to “CameraRelative” anymore, so I researched it a little and found this way.

Anything incorrectly point will be edited, and I will appreciate the corrector.

13 Likes

Thank you for this, I didn’t know base camera ran the override function. This makes it even easier to control its behavior rather just deactivating it entirely.

2 Likes