OrbitCamera

A third-person chase camera: it sits behind and above a target entity, looking at a point above the target's feet, and swings round that point on a sphere. A look vector (e.g. a right stick) orbits it (x) and tilts it (y); recenter() swings it back behind the target. It never drifts behind a moving target on its own, so camera-relative movement (see BGE.Math.cameraRelativeMove()) runs straight instead of curving. lockOn() turns it to keep a second entity (e.g. an enemy) in view beyond the target.

It's a BGE.FollowCamera, so a scene can swap it for another rig (e.g. a BGE.ChaseCamera). Give it a BGE.CameraBoom to pull it in front of walls between it and the target. Call update() after everything has moved, e.g. in the scene's onPostUpdate():

m.orbit = new BGE.OrbitCamera(camera, player, { boom: new BGE.CameraBoom(m.game, {collidableFlags: CAMERA_BLOCKER}) }) m.orbit.update(dt, m.game.controls.getRawAxis("look"))

Properties

  • camera (BGE.Camera3d)
  • target (BGE.GameEntity)
  • heading (float) — Ground heading the camera looks along (heading 0 faces -z)
  • distance (float) — Horizontal distance behind the target at rest, in world units
  • height (float) — Height of the camera above the target's position at rest
  • lookHeight (float) — Height above the target's position of the point the camera looks at
  • minHeight (float) — The camera never goes lower than this above the target's position
  • orbitSpeed (float) — Radians/sec at full look
  • recenterSpeed (float) — Radians/sec while recentering (tilt eases back at a quarter of this)
  • tilt (float) — Tilt added to the resting angle, in radians; positive looks further down on the target
  • tiltSpeed (float) — Radians/sec at full look
  • minTilt (float)
  • maxTilt (float)
  • boom (BGE.CameraBoom) — Optional: pulls the camera in front of blockers
  • lockTurnSpeed (float) — Radians/sec while turning to keep a locked-on entity in view
  • lockTilt (float) — Tilt while locked on, e.g. positive to look down on the ground between the target and the
  • lockTarget (BGE.GameEntity) — The entity the camera keeps in view beyond the target, or invalid; see lockOn()
  • lockDeadZone (float) — Locked on, the camera doesn't turn while the entity is in the middle lockDeadZone of the
  • lockEase (float) — Locked on, an exponential ease: each frame the camera turns 1 - e^(-lockEase * dt) of the
  • recentering (boolean)
  • noLook (dynamic) — follow()'s look when the input has none; update() only reads it
  • lockRefocusing (boolean) — Turning back toward a lockOn() entity that left the dead zone

Constructor

new OrbitCamera( camera: BGE.Camera3d, target: BGE.GameEntity, options?: BGE.OrbitCameraOptions, ): OrbitCamera

Places the camera straight away, behind the target unless options.heading says otherwise, and levels its roll (e.g. left over from a BGE.ChaseCamera).

Parameters


Instance Methods

snapBehind(heading: float): void

Puts the camera straight behind the target, looking along heading, level and with no easing, e.g. after a respawn or a cut. Cancels a recenter(); a lockOn() carries on.

Parameters

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

Returns

  • void

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

update() with a BGE.FollowCameraInput: reads look (none if left out).

Parameters

Returns

  • void

recenter(): void

Starts swinging the camera back behind the target, with the tilt back to rest. Any look input cancels it.

Returns

  • void

lockOn(entity: BGE.GameEntity): void

Turns the camera to look past the target at entity and keep it there, tilted to lockTilt. Look input is ignored until releaseLock(), or until entity is invalidated.

Parameters

  • entity (BGE.GameEntity) — what to keep in view, e.g. a locked-on enemy

Returns

  • void

releaseLock(): void

Stops following a lockOn() entity; the camera stays where it is.

Returns

  • void

isLocked(): boolean

Whether the camera is keeping a lockOn() entity in view.

Returns

  • boolean

isRecentering(): boolean

Whether a recenter() is still under way.

Returns

  • boolean

update(dt: float, look: BGE.Math.Vector): void

Orbits/tilts by the look vector (or turns toward a lockOn() entity), then moves the camera.

Parameters

  • dt (float) — seconds since last frame
  • look (BGE.Math.Vector) — x orbits (positive turns the camera clockwise seen from above), y tilts (positive looks up); each -1..1. Ignored while locked on.

Returns

  • void

lockTargetScreenOffset(): float

How far off the middle of the screen the lockOn() entity is, across: 0 in the middle, 1 at the left or right edge, more when off screen. Measured on the ground from where the camera is, so it ignores tilt.

Returns

  • float

turnTowardLockTarget(dt: float): void

protected

Parameters

  • dt (float)

Returns

  • void

getLookAt(): BGE.Math.Vector

The point the camera looks at: lookHeight above the target.

Returns

  • BGE.Math.Vector

apply(dt: float): void

protected

Parameters

  • dt (float)

Returns

  • void