demo · v144

FPS Camera

A first-person shooter camera, the canonical Pointer Lock workload. Tap the arena to lock the pointer; mouse-look pans the scene; click to shoot. On Android with an attached mouse or trackpad, the same primitives now apply — v144 closes the platform gap.

pointer lock: checking… · status: unlocked

hits: 0 · shots: 0 · accuracy:
pitch:
yaw:
click arena to lock · click again to shoot · esc to release

the API

arena.addEventListener("click", () => {
  if (document.pointerLockElement !== arena) {
    arena.requestPointerLock({ unadjustedMovement: true });
  } else {
    shoot();
  }
});

document.addEventListener("mousemove", (e) => {
  if (document.pointerLockElement === arena) {
    yaw += e.movementX * sensitivity;
    pitch += e.movementY * sensitivity;
  }
});

see also