I don’t know how long this has been happening, but less than 2 months I believe. I just noticed it today.
Expected behavior: When mouse is locked using MouseBehavior
, then calling GetMouseDelta()
should return the delta mouse position from its last position from the previous frame.
Current broken behavior: When mouse is locked using MouseBehavior
and the mouse has not yet been moved, then GetMouseDelta()
will return the distance from the last position when the mouse was locked before.
In other words, you get a sporadic delta value the first time it’s called with the mouse locked.
Repro:
- Open new place.
- Create LocalScript under StarterPlayerScripts:
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
RunService.Heartbeat:Connect(function()
local delta = UserInputService:GetMouseDelta()
print(delta)
end)
-- Lock cursor when mouse down:
UserInputService.InputBegan:Connect(function(input, processed)
if (processed) then return end
if (input.UserInputType == Enum.UserInputType.MouseButton1) then
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
end
end)
-- Unlock cursor when mouse up:
UserInputService.InputEnded:Connect(function(input)
if (input.UserInputType == Enum.UserInputType.MouseButton1) then
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
end
end)
- Run the game w/ player
- With Output window open, try to left-click or right-click without moving the mouse. Notice the sporadic delta value in output
- Move mouse around. Notice the correct delta being shown.
Conclusion: The delta position is incorrectly calculated until the mouse actually moves in Locked mode. It seems to still work normally online.