LittleJS 1.28.0

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:836

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, PI/2 looks straight down

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:865

Swing around behind the way the target moves

collideWalls : booleanrender3dExtras.js:887

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

distance : numberrender3dExtras.js:855

How long the pole is

dragButton : numberrender3dExtras.js:877

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

lockPointer : booleanrender3dExtras.js:879

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

lookSpeed : numberrender3dExtras.js:881

How far a pixel of mouse movement turns it

manualControl : booleanrender3dExtras.js:875

The mouse and a gamepad stick turn it

pitch : numberrender3dExtras.js:859

Angle of the pole above level

Lowest and highest pitch

Where the pole starts from the target, usually its head

smoothing : numberrender3dExtras.js:863

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

stick : numberrender3dExtras.js:883

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

stickSpeed : numberrender3dExtras.js:885

Radians a second a stick pushed all the way turns it

swingDelay : numberrender3dExtras.js:871

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

swingSmoothing : numberrender3dExtras.js:867

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

swingSpeed : numberrender3dExtras.js:869

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

What it follows; destroyed or undefined, the camera holds

useFacing : booleanrender3dExtras.js:873

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

wallMargin : numberrender3dExtras.js:889

How far in front of a wall it stays

wallSmoothing : numberrender3dExtras.js:891

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:1023

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 turns to look the way that one did

turn(yaw, pitch)render3dExtras.js:915

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

updateCamera()render3dExtras.js:941

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