Force shift lock without changing camera module

Why there is no simple way to just force shift lock for players without adding/changing functions in the player camera module,

I think its a bad idea to change the default player modules since it gets updated every once in a while which means you have to get back to your code to update it too, Is there any simpler way to just force it by changing a variable or by calling a function or something,

I have been looking into this for hours now and couldn’t find a solution.

2 Likes

I think UserInputService.MouseBehaviour.LockCenter could help you with this.
https://developer.roblox.com/en-us/api-reference/property/UserInputService/MouseBehavior

2 Likes

It only looks the mouse not the rotational movement, appreciate your reply and it certainly helps.

1 Like

I tried this one before but it just locked the mouse in the center and I was able to move it freely. I am not sure if there was a problem in my script but this is what happened

1 Like

If you mean the body rotation with the rotational movement it can be done manually afterwards as well.

local RunService = game:GetService("RunService") 
local UserInputService = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Character = Player.Character

local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local Mouse = Player:GetMouse()

RunService.RenderStepped:Connect(function()
	UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter --//Changing Mouse Behavior
	local HMRPosition =  HumanoidRootPart.Position --//Getting the HumanoidRootPart's position
MousePosition = Mouse.Hit.Position --//Getting the mouse position
	HumanoidRootPart.CFrame = CFrame.new(HMRPosition, Vector3.new(MousePosition.X, HMRPosition.Y, MousePosition.Z)) --//Setting the CFrame of our HumanoidRootPart
end)
3 Likes

That seems to be exactly what im looking for, but does it work on mobile tho since mobile doesn’t have a cursor(mouse) and also how can i set an offset to it so it would be on the top right of the player shoulder?

Sorry for the late reply i was really busy, really appreciate your help

2 Likes

Since there is no mouse on mobile I thought it wouldn’t be a problem however I made a mistake there, I made the character face where the mouse points at which is a problem since in mobile this will make the player look where they touch.

So I changed it to look at where the camera is looking and made it so the camera focuses on the Right Upper Arm of the character which would be the shoulder.

local RunService = game:GetService("RunService") 
local UserInputService = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Character = Player.Character

local Camera = workspace.CurrentCamera

local RightUpperArm = Character:WaitForChild("RightUpperArm")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local Mouse = Player:GetMouse()

RunService.RenderStepped:Connect(function()
	    UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter --//Changing Mouse Behavior
	
	--//Rotating character
      	local HMRPosition =  HumanoidRootPart.Position --//Getting the HumanoidRootPart's position
	
	    HumanoidRootPart.CFrame = CFrame.new(HMRPosition, HMRPosition + Vector3.new(Camera.CFrame.LookVector.X,0,Camera.CFrame.LookVector.Z))
	--//Making the camera on shoulder
	    Camera.CameraSubject = RightUpperArm
end)
3 Likes

The issue in the previous script was that you forgot the local before a variable but i fixed it and it works perfectly, for this new version tho (the upper shoulder view) it was what i need and I understand it perfectly, You have no idea howmuch i appreciate your help, Thanks man.

2 Likes

I used this “change the torso CFrame every render step” method as well, but there seems to be a network interpolation problem with the character parts.

On the client’s screen, it works fine:

However, on other player’s screens, it’s all janky looking:

My guess is that there’s a disagreement on the server as to how your character is rotated. It’s receiving packets that say you’re oriented in the camera’s (mouse-locked) direction, but also receiving packets sent between render steps which say you’re oriented in the movement direction, and the server tries to interpolate between these rotation updates.

It looks like there used to be a way to apply the character lock without needing to fork the camera module,

but it doesn’t work anymore.

2 Likes