In studio (e.g., via a plugin), if you lock the mouse position (Enum.MouseBehavior.LockCurrentPosition
), move the mouse, unlock the mouse position (Enum.MouseBehavior.Default
), and then tap right click, your camera will jump.
For a simple repro, save this script as a plugin:
--!strict
--This script will lock the mouse in place when the user left clicks. This demonstrates a bug, where
--if you depress the left mouse button, move the mouse, release the left mouse button, then click
--the right mouse button (even instantaneously), the camera will jump.
local UIS = game:GetService("UserInputService");
local mouse1Down = false;
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent and input.UserInputType == Enum.UserInputType.MouseButton1 then
mouse1Down = true;
UIS.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition;
end
end);
UIS.InputEnded:Connect(function(input, gameProcessedEvent)
if mouse1Down and input.UserInputType == Enum.UserInputType.MouseButton1 then
mouse1Down = false;
UIS.MouseBehavior = Enum.MouseBehavior.Default;
end
end);
Here is a video demonstrating the issue. The green circle indicates that I’ve depressed the left mouse button; the red circle indicates that I’ve depressed the right mouse button. I also draw a green/red line across the screen to show how I’m attempting to move the mouse (captured via InputObject.Delta
).
You can see I left click, drag the mouse upward, release left click, and then tap right click – my camera jumps.
Expected behavior
I would not expect the camera to jump like that. It’s as if it’s “built up” a whole bunch of delta and unleashes it all at once.
Customer Impact
My hope was to use a particular UX for a plugin of mine where the user left clicks to position a tree, then they can drag the mouse up/down to grow/shrink the tree. However, with this camera bug, this UX is very annoying. It works, and I can implement the grow/shrink behavior, but the user will have to deal with unpredictable camera jumps afterward.
So essentially, I’m boxed out from any click-and-drag-with-locked-mouse user interactions.
Additional Notes
This isn’t an issue when you have a character, BUT unexpectedly, if the mouse gets locked, the camera gets affected by any mouse movement. So, the UX I described up above would be even worse if I tried to implement this in a tool, as the camera would be moving around despite that the user hasn’t held down right click. The workaround here would be to implement your own camera, but in studio, I don’t have that flexibility.