SpectatorCamera

@three-blocks/proPhysicsCameraSpectatorWebGPUWebGL
new SpectatorCamera(physics : Object, options : Object)
Extends
PhysicsCamera

SpectatorCamera - Camera for spectating any physics body

Attaches to kinematic or dynamic bodies and provides multiple view modes:

  • native: Use the body's camera if available, else first-person
  • firstPerson: First-person view from body's position/rotation
  • rts: Overhead RTS-style view centered on the body
  • free: Detached camera (no automatic positioning)

Designed for spectating AI agents, multiplayer scenarios, and debugging.

Constructor Parameters
physicsObject
Physics instance
optionsoptionalObject
Camera options
Default is {}.
  • eyeHeightoptionalnumber
    Eye height offset for first-person mode
    Default is 1.7.
  • fovoptionalnumber
    Field of view
    Default is 70.
  • nearoptionalnumber
    Near clipping plane
    Default is 0.1.
  • faroptionalnumber
    Far clipping plane
    Default is 1000.
Example
import { SpectatorCamera } from '@three-blocks/pro';

const spectator = new SpectatorCamera(physics, {
  eyeHeight: 1.7,
});

// Attach to a bot
spectator.attach(bot.body);

// Override with RTS style
spectator.setMode('rts', { distance: 30, tilt: Math.PI / 3 });

// Return to body's native view
spectator.setMode('native');

// Detach (returns to free camera)
spectator.detach();

// In animation loop
spectator.update(delta);
renderer.render(scene, spectator);

Properties

.eyeHeight : number

Eye height offset for first-person mode.

.attachedBody :

Get currently attached body.

.mode :

Get current view mode.

.isAttached :

Check if camera is attached to a body.

Methods

attach#

attach(body : Object) : SpectatorCamera

Attach to a physics body.

Parameters
bodyObject
KinematicBody or DynamicBody to spectate
Returns
SpectatorCamera — This instance for chaining

detach#

detach() : SpectatorCamera

Detach from current body.

Returns
SpectatorCamera — This instance for chaining

setMode#

setMode(mode : 'native'|'firstPerson'|'rts'|'free', config : Object) : SpectatorCamera

Set spectator view mode.

Parameters
mode'native' | 'firstPerson' | 'rts' | 'free'
View mode
configoptionalObject
Mode-specific configuration
Default is {}.
  • distanceoptionalnumber
    Distance from body (RTS mode)
    Default is 30.
  • tiltoptionalnumber
    Camera tilt angle (RTS mode)
    Default is Math.PI/3.
Returns
SpectatorCamera — This instance for chaining

update#

update(delta : number)

Update camera state. Call each frame.

Parameters
deltanumber
Time delta in seconds