[page:EventDispatcher] →

# [name]

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.

## Import

[name] is an add-on, and must be imported explicitly. See [link:#manual/introduction/Installation Installation / Addons].

`import { PointerLockControls } from 'three/addons/controls/PointerLockControls.js';`

## Code Example

`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'; } );`

## Examples

[example:misc_controls_pointerlock misc / controls / pointerlock ]

## Constructor

### [name]( [param:Camera camera], [param:HTMLDOMElement domElement] )

[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].

## Events

### change

Fires when the user moves the mouse.

### lock

Fires when the pointer lock status is "locked" (in other words: the mouse is captured).

### unlock

Fires when the pointer lock status is "unlocked" (in other words: the mouse is not captured anymore).

## Properties

### [property:HTMLDOMElement domElement]

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.

### [property:Boolean isLocked]

Whether or not the controls are locked.

### [property:Float maxPolarAngle]

Camera pitch, upper limit. Range is 0 to Math.PI radians. Default is Math.PI.

### [property:Float minPolarAngle]

Camera pitch, lower limit. Range is 0 to Math.PI radians. Default is 0.

### [property:Float pointerSpeed]

Multiplier for how much the pointer movement influences the camera rotation. Default is 1.

## Methods

See the base [page:EventDispatcher] class for common methods.

### [method:undefined connect] ()

Adds the event listeners of the controls.

### [method:undefined disconnect] ()

Removes the event listeners of the controls.

### [method:Vector3 getDirection] ( [param:Vector3 target] )

[page:Vector3 target]: The target vector.

Returns the look direction of the camera.

### [method:undefined lock] ()

Activates the pointer lock.

### [method:undefined moveForward] ( [param:Number distance] )

[page:Number distance]: The signed distance.

Moves the camera forward parallel to the xz-plane. Assumes camera.up is y-up.

### [method:undefined moveRight] ( [param:Number distance] )

[page:Number distance]: The signed distance.

Moves the camera sidewards parallel to the xz-plane.

### [method:undefined unlock] ()

Exits the pointer lock.

## Source

[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/PointerLockControls.js examples/jsm/controls/PointerLockControls.js]