The implementation of this class is based on the [link:https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API Pointer Lock API]. [name] 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';
} );
[example:misc_controls_pointerlock misc / controls / pointerlock ]
[page:Camera camera]: The camera of the rendered scene.
[page:HTMLDOMElement domElement]: The HTML element used for event listeners.
Creates a new instance of [name].
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).
The HTMLDOMElement used to listen for mouse / touch events. This must be passed in the constructor; changing it here will not set up new event listeners.
Whether or not the controls are locked.
Camera pitch, upper limit. Range is 0 to Math.PI radians. Default is Math.PI.
Camera pitch, lower limit. Range is 0 to Math.PI radians. Default is 0.
See the base [page:EventDispatcher] class for common methods.
Adds the event listeners of the controls.
Removes the event listeners of the controls.
[page:Vector3 target]: The target vector.
Returns the look direction of the camera.
Activates the pointer lock.
[page:Number distance]: The signed distance.
Moves the camera forward parallel to the xz-plane. Assumes camera.up is y-up.
[page:Number distance]: The signed distance.
Moves the camera sidewards parallel to the xz-plane.
Exits the pointer lock.
[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/PointerLockControls.js examples/jsm/controls/PointerLockControls.js]