Inheritance: EventDispatcher → Controls →
The implementation of this class is based on the Pointer Lock API. PointerLockControls is a perfect choice for first person 3D games.
const controls = new PointerLockControls( camera, document.body );
// add event listener to show/hide a UI (e.g. the game's menu)
controls.addEventListener( 'lock', function () {
menu.style.display = 'none';
} );
controls.addEventListener( 'unlock', function () {
menu.style.display = 'block';
} );
PointerLockControls is an addon, and must be imported explicitly, see Installation#Addons.
import { PointerLockControls } from 'three/addons/controls/PointerLockControls.js';
Constructs a new controls instance.
camera
The camera that is managed by the controls.
domElement
The HTML element used for event listeners.
Default is null.
Whether the controls are locked or not.
Default is false.
Camera pitch, upper limit. Range is '[0, Math.PI]' in radians.
Default is Math.PI.
Camera pitch, lower limit. Range is '[0, Math.PI]' in radians.
Default is 0.
Multiplier for how much the pointer movement influences the camera rotation.
Default is 1.
Returns the look direction of the camera.
v
The target vector that is used to store the method's result.
Returns: The normalized direction vector.
Activates the pointer lock.
unadjustedMovement
Disables OS-level adjustment for mouse acceleration, and accesses raw mouse input instead. Setting it to true will disable mouse acceleration.
Default is false.
Moves the camera forward parallel to the xz-plane. Assumes camera.up is y-up.
distance
The signed distance.
Moves the camera sidewards parallel to the xz-plane.
distance
The signed distance.
Exits the pointer lock.
Fires when the user moves the mouse.
Fires when the pointer lock status is "locked" (in other words: the mouse is captured).
Fires when the pointer lock status is "unlocked" (in other words: the mouse is not captured anymore).