LittleJS 1.30.1

Render3D

ThirdPersonCamera3D

ThirdPersonCamera3D - A camera on a pole from the player, swinging around behind it as it moves

  • The pole starts at a pivot, pivotOffset from the target, usually its head, turns by yaw and pitch, and the camera sits at its end, distance away, looking back at the pivot
  • autoSwing, on by default, swings it around behind the way the target moves across the ground, eased by swingSmoothing, only while the target moves faster than swingSpeed; useFacing swings it behind the target's own facing instead, for a player that turns
  • The mouse, dragging dragButton or with the pointer locked, and a gamepad stick turn it by hand when manualControl is on, and turning by hand holds the swing for swingDelay seconds; turn() does the same for a game's own controls
  • A wall between the pivot and the camera, the level or a solid object, pulls it in, in front of the wall, and it eases back out once clear
  • A camera of the camera plugin: the newest made drives the view, after the objects move each update
  • Destroy it to hand the camera back

Extends EngineObject3D

Constructor

new ThirdPersonCamera3D(target, distance, pitch)render3dExtras.js:1320

Make a third person camera, the view goes to it at once

target EngineObject3D|Vector3 optional

What to follow, an object or a position

distance number optional, default 6

How long the pole is

pitch number optional, default 0.3

Angle of the pole above level, held to pitchRange, -.4 to 1.2 by default

const camera = new ThirdPersonCamera3D(player); // follow the player from 6 units back
camera.autoSwing = false;                       // a shooter turns it only by hand

Members

Methods

Inherited from EngineObject3D

Inherited from EngineObject

Members

autoSwing : booleanrender3dExtras.js:1349

Swing around behind the way the target moves

collideWalls : booleanrender3dExtras.js:1371

Pull in, in front of a wall between the pivot and the camera

distance : numberrender3dExtras.js:1339

How long the pole is

dragButton : numberrender3dExtras.js:1361

Mouse button that turns it while held, 0 is left and 2 is right

lockPointer : booleanrender3dExtras.js:1363

Capture the mouse on a press of dragButton, so turning needs no button held

lookSpeed : numberrender3dExtras.js:1365

How far a pixel of mouse movement turns it

manualControl : booleanrender3dExtras.js:1359

The mouse and a gamepad stick turn it

Angle of the pole above level

Lowest and highest pitch

Where the pole starts from the target, usually its head

smoothing : numberrender3dExtras.js:1347

Seconds the pivot takes to close most of the gap to the target, 0 sticks to it

Which gamepad stick turns it, 1 is usually the right one

stickSpeed : numberrender3dExtras.js:1369

Radians a second a stick pushed all the way turns it

swingDelay : numberrender3dExtras.js:1355

Seconds after turning by hand before it swings on its own again

swingSmoothing : numberrender3dExtras.js:1351

Seconds the swing takes to close most of the gap, how tight it is

swingSpeed : numberrender3dExtras.js:1353

World units a second the target must move across the ground for it to swing

What it follows; destroyed or undefined, the camera holds

targetFrom : Vector3|undefinedrender3dExtras.js:1381
useFacing : booleanrender3dExtras.js:1357

Swing behind the target's own facing, its getForward3D, instead of the way it moves

wallMargin : numberrender3dExtras.js:1373

How far in front of a wall it stays

wallSmoothing : numberrender3dExtras.js:1375

Seconds it takes to ease most of the way back out once clear of a wall

Angle of the pole around the target, 0 puts the camera on the +Z side looking -Z

Methods

Make this the camera that drives the view

destroy(immediate)render3dExtras.js:1510

Let go of the mouse and stop driving the camera

immediate boolean optional

Camera controls draw nothing

Put it on the target at once, with no easing, for a level start or a teleport, the camera too when this one drives it; with no target it stays where the camera is, looking the way it looks

Taking over from another camera, it starts where that one left the view, looking the way it looked, and eases to its target from there

turn(yaw, pitch)render3dExtras.js:1403

Turn it by hand, as the mouse and stick do, which holds the swing for swingDelay seconds

yaw number

Radians to turn around the target

pitch number optional, default 0

Radians to tilt the pole up

Turn, swing and pull in, and set the camera, called by the camera plugin after the objects update