Problem in rotating

Hi, I’m making a custom shift lock system, and I’m rotating the camera, and it doesn’t rotate correctly, here’s the code:

local mouse = game.Players.LocalPlayer:GetMouse();

local cam = workspace.CurrentCamera

mouse.Move:Connect(function()
	
	local userInputService = game:GetService("UserInputService");
	
	userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter

	
	local pitch, yaw, roll = mouse.Hit:ToEulerAnglesYXZ()
	
	cam.CFrame = CFrame.new(cam.CFrame.Position) * CFrame.Angles(0, math.rad(yaw * 30), 0)
end)

Also, video here: robloxapp-20200902-1209328 on Vimeo

Help is appreciated! Thanks.

1 Like

Is the mouse locked in the center?

No, the code doesn’t lock it. Idk why

Try this:

local mouse = game.Players.LocalPlayer:GetMouse();

local cam = workspace.CurrentCamera

mouse.Move:Connect(function()
	
	local pitch, yaw, roll = mouse.Hit:ToEulerAnglesYXZ()
	
	cam.CFrame = CFrame.new(cam.CFrame.Position) * CFrame.Angles(0, math.rad(yaw * 30), 0)
end)

local runService = game:GetService("RunService");

local function render_Step()
	
	local userInputService = game:GetService("UserInputService");
	
	userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
end

runService.RenderStepped:Connect(render_Step)

My problem is rotating the camera, this is not my problem
well thx

It is happening because the mouse is reaching the limit of the side before it can complete the spin.
You have to lock it in the center to prevent it

Yeah, how do I prevent it from doing that?

Yes, use my code above that should do it.

Nope. The code that you provided didn’t rotate the camera fully and also it didn’t lock the mouse.

Return to the code you had, and add another LocalScript:

local runService = game:GetService("RunService");

local function render_Step()
	
	local userInputService = game:GetService("UserInputService");
	
	userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter -- Should lock the mouse
end

runService.RenderStepped:Connect(render_Step)

It’s not working. How?? I don’t even know why

Does it lock the mouse in the center?

No, it keeps moving. Well it should work.

The script is a LocalScript right? It isn’t supposed to happen.

Oh, when I right clicked then it locked mouse, and didn’t rotate the character.

Yes, because Mouse.Move() doesn’t fire when the mouse is locked , and it is the only way to prevent the issue you considered. You can force the default. Read this article.

Which article? You didn’t provide any.

Here: