ChaseCamera

A chase camera for vehicles that pitch and roll (planes, spaceships, boats): it sits behind a target entity along its heading and pitch, eased so turns swing the view round rather than snapping it, and rolls with the target's bank. Unlike BGE.OrbitCamera there's no look input: the target's own attitude, passed to update() each frame, steers it.

It's a BGE.FollowCamera, so a scene can swap it for another rig (e.g. a BGE.OrbitCamera). Give it a terrain to keep the camera above the ground. Call update() after everything has moved, e.g. in the scene's onPostUpdate():

m.chase = new BGE.ChaseCamera(camera, plane, {heading: plane.heading, terrain: m.terrain}) m.chase.update(dt, plane.heading, plane.pitch, plane.bank)

Properties

  • camera (BGE.Camera3d)
  • target (BGE.GameEntity)
  • distance (float) — Distance behind the target, in world units, measured along the camera's eased heading and
  • height (float) — Raised this far above that point, straight up in world space
  • lookDown (float) — Radians the camera looks below its own pitch, so the target sits low with more to see ahead
  • followRate (float) — How quickly heading and pitch catch up with the target, 1/seconds (higher is tighter)
  • rollRate (float) — How quickly the roll catches up with the target's bank, 1/seconds
  • pitchFollow (float) — Fraction of the target's pitch the camera takes up
  • maxPitch (float) — The camera's pitch is kept within +/- this, radians
  • rollFollow (float) — Fraction of the target's bank the camera rolls by; under 1 keeps the target looking banked
  • terrain (BGE.DrawableVoxelTerrain) — Optional: the camera stays groundClearance above it
  • groundClearance (float)
  • heading (float) — The eased attitude the camera is following: heading (0 faces -z, clockwise seen from above),
  • pitch (float)
  • roll (float)

Constructor

new ChaseCamera( camera: BGE.Camera3d, target: BGE.GameEntity, options?: BGE.ChaseCameraOptions, ): ChaseCamera

Places the camera straight away, behind the target along options.heading (default the target's rotation.y), level and unrolled.

Parameters


Instance Methods

snapBehind(heading: float): void

Puts the camera straight behind the target at heading, level and unrolled, with no ease, e.g. when the target respawns.

Parameters

  • heading (float) — radians; 0 faces -z, increasing turns clockwise seen from above

Returns

  • void

update( dt: float, heading: float, pitch?: float, bank?: float, ): void

Eases toward the target's attitude, then moves the camera.

Parameters

  • dt (float) — seconds since last frame
  • heading (float) — the target's heading, radians; 0 faces -z, increasing turns clockwise seen from above
  • pitch (float, optional, default: 0) — the target's pitch, radians, positive nose up
  • bank (float, optional, default: 0) — the target's bank, radians; becomes the camera's rollDegrees (times rollFollow)

Returns

  • void

follow(dt: float, input: BGE.FollowCameraInput): void

update() with a BGE.FollowCameraInput: reads heading (default the target's rotation.y), pitch and bank (default 0).

Parameters

Returns

  • void

getLookAt(): BGE.Math.Vector

The point the camera follows: the target's position. The camera sits height above the line behind it and looks lookDown below that line, so the target sits a little low on screen.

Returns

  • BGE.Math.Vector

apply(): void

protected

Returns

  • void