UserInputService:GetMouseDelta() broken in Studio

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:

  1. Open new place.
  2. 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)
  1. Run the game w/ player
  2. With Output window open, try to left-click or right-click without moving the mouse. Notice the sporadic delta value in output
  3. 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.

14 Likes

The change that caused this has been reverted, sorry for the inconvenience.

No live games will have been impacted by this, the change was indeed limited to Studio only.

1 Like

Cool, thank you for the update!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.