Skip to content

Fix mouse movement calculation to be pointer-lock aware#8681

Draft
4ian wants to merge 2 commits into
masterfrom
claude/nice-hopper-cDttW
Draft

Fix mouse movement calculation to be pointer-lock aware#8681
4ian wants to merge 2 commits into
masterfrom
claude/nice-hopper-cDttW

Conversation

@4ian

@4ian 4ian commented Jun 6, 2026

Copy link
Copy Markdown
Owner

This PR fixes mouse movement tracking in the InputManager to properly handle both locked and unlocked pointer states. Previously, the code relied on browser-provided movementX/Y values unconditionally, which are unreliable across browsers when the pointer is not locked. Now the InputManager intelligently switches between using browser movement deltas (when pointer is locked) and computing movement from cursor position deltas (when pointer is not locked).

This was done previously only in the 3D editor (which was simplified).

To check:

  • No regression on Chrome/Safari/Electron on games including those locking the pointers and those not locking it.
  • Working on Firefox on games including those not locking the pointer.

claude added 2 commits June 6, 2026 10:06
The browser's MouseEvent.movementX/Y are only reliable while the pointer
is locked. When not locked, they are inconsistent across browsers: notably
Firefox adds the game canvas offset to them, so a first-person camera keeps
drifting/sticking (e.g. stuck looking up) unless the game runs fullscreen.

Now the movement deltas from the browser are only used when the pointer is
locked (where the cursor position is frozen). Otherwise the InputManager
derives the movement from the change of the cursor position, which is
consistent across browsers and already expressed in game resolution units.

The reference position is invalidated when the pointer lock state changes or
when the mouse leaves/enters the canvas, to avoid reporting a spurious jump.

Relates to #6338.
Now that InputManager.getMouseMovementX/Y is itself pointer-lock aware
(browser deltas when locked, cursor position delta otherwise), the in-game
editor no longer needs to branch on the pointer lock state or track the
previous cursor position itself.

This removes the duplicated ternary in both editor camera controllers, the
now-unused renderer locals and the _lastCursorX/_lastCursorY bookkeeping.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants