Force a third-person camera(shift lock)

Hello. I am trying to force-activate/deactivate shift lock in my game.

However, when I looked it up in the dev forums, none of the solutions helped me. It seemed to work for others, but not for me. Does anyone have a simple solution for this?

1 Like

I was definitely struggling with this too a couple days ago. I couldn’t figure out a way to “force” shift lock, but I was able to make the player face the direction of the camera. Is that what you want, or does it need to be shift lock?

1 Like

Making the player face the camera is not exactly difficult. However, I’m sure there is a way to modify some core scripts to open and close shift-lock. Does your way of making the mouse face the camera involve using renderstep?

1 Like

Yeah my method does include RenderStep. The following code doesn’t set it exactly to shift lock, but it locks the mouse in the center of the screen. If they need to use a GUI they can hold ALT. You could combine this with a RenderStep to make them face the camera direction. There is probably a better method though.

local userInputService = game:GetService("UserInputService")
game:GetService("RunService").RenderStepped:Connect(function() -- you could replace this with InputBegan and InputEnded if you want
	if userInputService:IsKeyDown(Enum.KeyCode.LeftAlt) == true or userInputService:IsKeyDown(Enum.KeyCode.RightAlt) == true then
		userInputService.MouseBehavior = Enum.MouseBehavior.Default
		userInputService.MouseIconEnabled = true
	else
		userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
		userInputService.MouseIconEnabled = true --change to false if you want invisible mouse
	end
end)
1 Like