Class: KeyboardControls

KeyboardControls(camera, target, element, optionsopt, configopt)

Shared `keyboard + pointer` controls for character cameras.

Constructor

new KeyboardControls(camera, target, element, optionsopt, configopt)

Parameters:
Name Type Attributes Description
camera Camera Controlled camera.
target Object3D Target object, that the camera follows.
element HTMLElement DOM element, that receives pointer input.
options KeyboardControlsOptions <optional>
Optional controls configuration.
config Object <optional>
Internal configuration for derived controls.
Properties
Name Type Attributes Default Description
cameraConstructor function <optional>
Camera Expected camera constructor for validation.
controlsName string <optional>
'KeyboardControls' Controls class name for error messages.
bobbingMode string | null <optional>
null Camera mode, that enables bobbing (or null to disable).
Source:

Classes

KeyboardControls

Methods

applyCameraTransform(movement, cameraState, camera, target)

Applies camera transforms for the active camera type.
Parameters:
Name Type Description
movement MovementData Movement data.
cameraState CameraState Derived camera state.
camera Camera Controlled camera.
target Object3D Controlled target.
Source:

dispose()

Disposes the controller by removing all event listeners.
Source:

setCamera(camera)

Replaces the controlled camera.
Parameters:
Name Type Description
camera Camera New controlled camera instance.
Source:

setEnabled(enabled)

Enables or disables input listeners without destroying the controls.
Parameters:
Name Type Description
enabled boolean True to enable input, false to disable.
Source:

setTarget(target)

Replaces the target object.
Parameters:
Name Type Description
target Object3D New target object.
Source:

update(deltaSeconds)

Updates the controlled camera and target based on input and time delta.
Parameters:
Name Type Description
deltaSeconds number Time delta in seconds.
Source:

updateTargetRotation(target, movement, azimuthRadians)

Updates target rotation based on movement and orientation.
Parameters:
Name Type Description
target Object3D Controlled target.
movement MovementData Movement data.
azimuthRadians number Current yaw angle in radians.
Source:

(static) assertCameraState(cameraState, context) → {void}

Parameters:
Name Type Description
cameraState unknown Candidate camera state.
context string Error message context.
Source:
Throws:
When `cameraState` does not match CameraState.
Type
TypeError
Returns:
Type
void

(static) assertMovementData(movement, context) → {void}

Parameters:
Name Type Description
movement unknown Candidate movement data.
context string Error message context.
Source:
Throws:
When `movement` does not match MovementData.
Type
TypeError
Returns:
Type
void