✓ Accepted answer
You can use UserInputService. Mouse.Move works fine when the mouse is free, like you said, but you can use UserInputService to determine the mouse delta while the mouse is locked (either because you're in first person or you set the MouseBehavior to LockCenter, or some other reason).
The following code demonstrates both. Throw it in a LocalScript somewhere and look how the function that's outputting meaningful values switches when you're in first person vs. freely moving the mouse.
local mouse = game.Players.LocalPlayer:GetMouse();
local lastX, lastY = 0, 0;
mouse.Move:connect(function()
print("Move: (" ..
tostring(mouse.X - lastX) .. ", " ..
tostring(mouse.Y - lastY) .. ")"
);
lastX = mouse.X;
lastY = mouse.Y;
end)
local userinput = game:GetService("UserInputService");
userinput.InputChanged:connect(function(inputObj)
if (inputObj.UserInputType == Enum.UserInputType.MouseMovement) then
local dx = inputObj.Delta.X;
local dy = inputObj.Delta.Y;
print("UI: (" ..
tostring(dx) .. ", " ..
tostring(dy) .. ")"
);
end
end)
1 comment
I actually found an alternative to what I needed to do, but I appreciate the answer and I'm sure some other people that read your answer were helped as well. Thanks! :)