How can I make the camera move when I'm moving my mouse without right-clicking?

So , I’m working on a third-person shooter game and I’m currently working on some guns for my game and I have no idea how to make the camera move when you are moving the mouse without right-clicking (just like in shift-lock) . I tried to find a solution for my problem but I couldn’t find anything. Could anyone help me with my problem? :smile:

Try taking a look at, UserInputService | Documentation - Roblox Creator Hub.
I think you are looking to lock the mouse to the center of the screen.

1 Like

I already locked the mouse to the center of the screen. :wink: I want to make the player’s screen move when she/he moves his/her mouse (just like when you’re zoomed in or you’re shiftlocked)

1 Like

Then you want to use mouse delta, which will tell you what you need to know to make the camera move when moving your mouse and with a locked cursor.

2 Likes

I have no idea how to do it :confused: I tried searching it up but i couldn’t find any examples of how to do it. Maybe i’m just locking the mouse in an incorrect way :thinking: ; here is how do it:

game:GetService('RunService').RenderStepped:Connect(function()  
game:GetService('UserInputService').MouseBehavior = Enum.MouseBehavior.LockCenter 
end) 

I replied to a similar post a while ago, which may be helpful to you.

3 Likes

local UserInputService = game:GetService(“UserInputService”)
local RunService = game:GetService(“RunService”)
local Players = game:GetService(“Players”)

local player = Players.LocalPlayer
local Camera = workspace.CurrentCamera
local sensitivity = 0.2 – Adjust speed

local lastMousePos = Vector2.new()
local isFirstFrame = true
local shouldRun = true – Controls whether the loop runs

– Function to check if “stopautomouse” exists
local function checkStopValue()
local character = player.Character
if character then
local stopValue = character:FindFirstChild(“stopautomouse”)
shouldRun = stopValue == nil – Stop if value exists, continue if deleted
end
end

– Listen for character changes (when the player respawns)
player.CharacterAdded:Connect(function(character)
character.ChildAdded:Connect(checkStopValue) – Detect if “stopautomouse” is added
character.ChildRemoved:Connect(checkStopValue) – Detect if “stopautomouse” is removed
checkStopValue() – Run check immediately on spawn
end)

– Main camera movement loop
spawn(function()
while true do
if shouldRun then
local mousePos = UserInputService:GetMouseLocation()

		if isFirstFrame then
			lastMousePos = mousePos
			isFirstFrame = false
		else
			UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter  -- Locks mouse to center
			local delta = mousePos - lastMousePos
			lastMousePos = mousePos

			-- Rotating Camera
			local currentCFrame = Camera.CFrame
			local xRotation = CFrame.Angles(0, -math.rad(delta.X * sensitivity), 0)
			local yRotation = CFrame.Angles(-math.rad(delta.Y * sensitivity), 0, 0)

			Camera.CFrame = currentCFrame * xRotation * yRotation
		end
	else
		--make mouse free
		UserInputService.MouseBehavior = Enum.MouseBehavior.Default
	end

	RunService.RenderStepped:Wait()  -- Prevents infinite loop lag
end

end)