Capítulo 309 de 859

Chapter 309: FirstPersonControls

Core Idea

This class is an alternative implementation of FlyControls.

Key Concepts

  • autoForward : boolean: Whether the camera is automatically moved forward or not.
  • constrainVertical : boolean: Whether or not looking around is vertically constrained by verticalMin and verticalMax.
  • dampingFactor : number: How quickly the movement and look velocity catches up to the input. Lower values feel heavier (more inertia), 1 disables damping.
  • heightCoef : number: Determines how much faster the camera moves when it's y-component is near heightMax.
  • heightMax : number: Upper camera height limit used for movement speed adjustment.
  • heightMin : number: Lower camera height limit used for movement speed adjustment.
  • heightSpeed : boolean: Whether or not the camera's height influences the forward movement speed. Use the properties heightCoef, heightMin and heightMax for …
  • lookSpeed : number: The look around speed.
  • lookVertical : boolean: Whether it's possible to vertically look around or not.
  • mouseDragOn : boolean (readonly): Whether the mouse is pressed down or not.

Code Examples

import { FirstPersonControls } from 'three/addons/controls/FirstPersonControls.js';
  • What it demonstrates: Typical usage of FirstPersonControls.

Reference Tables

Constructor

Signature
new FirstPersonControls( object : Object3D, domElement : HTMLElement )

Properties

PropertyDescription
.autoForward : booleanWhether the camera is automatically moved forward or not.
.constrainVertical : booleanWhether or not looking around is vertically constrained by verticalMin and verticalMax.
.dampingFactor : numberHow quickly the movement and look velocity catches up to the input. Lower values feel heavier (more inertia), 1 disables damping.
.heightCoef : numberDetermines how much faster the camera moves when it's y-component is near heightMax.
.heightMax : numberUpper camera height limit used for movement speed adjustment.
.heightMin : numberLower camera height limit used for movement speed adjustment.
.heightSpeed : booleanWhether or not the camera's height influences the forward movement speed. Use the properties heightCoef, heightMin and heightMax for configuration.
.lookSpeed : numberThe look around speed.
.lookVertical : booleanWhether it's possible to vertically look around or not.
.mouseDragOn : boolean (readonly)Whether the mouse is pressed down or not.
.movementSpeed : numberThe movement speed.
.verticalMax : numberHow far you can vertically look around, upper limit. Range is 0 to Math.PI in radians.
.verticalMin : numberHow far you can vertically look around, lower limit. Range is 0 to Math.PI in radians.

Methods

MethodDescription
.handleResize()
`.lookAt( x : numberVector3, y : number, z : number ) : FirstPersonControls`

Key Takeaways

  1. FirstPersonControls extends: EventDispatcher → Controls
  2. Most relevant properties: autoForward, constrainVertical, dampingFactor, heightCoef.
  3. Key methods: handleResize, lookAt.

Connects To