Skip to content

NgtsPointerLockControls

NgtsPointerLockControls is a wrapper around Three.js PointerLockControls which provides first-person style controls by locking the mouse pointer.

Usage

import { NgtsPointerLockControls } from 'angular-three-soba/controls';
<ngts-pointer-lock-controls />

With Selector

Use the selector option to specify which elements should trigger pointer lock when clicked.

<ngts-pointer-lock-controls [options]="{ selector: '#lock-button' }" />

Handling Events

<ngts-pointer-lock-controls
(lock)="onLock()"
(unlock)="onUnlock()"
(change)="onChange($event)"
/>
onLock() {
console.log('Pointer locked');
}
onUnlock() {
console.log('Pointer unlocked');
}
onChange(event: any) {
console.log('Camera orientation changed');
}

Outputs

name type description
lock void Emits when the pointer is locked.
unlock void Emits when the pointer is unlocked.
change any Emits when the camera orientation changes.

Options

options input accepts any properties from PointerLockControls in addition to the following:

Properties

name type description
camera THREE.Camera The camera to control. If not provided, the default camera will be used.
domElement HTMLElement The DOM element to attach the controls to. If not provided, the current connected element will be used.
makeDefault boolean Whether to make this control the default one. Default: false
enabled boolean Whether the controls are enabled. Default: true
selector string A CSS selector for elements that will trigger pointer lock on click.