FollowCamera tracks a target (GameInstance or Vector2D) with configurable offsets.

Multiple FollowCameras can attach to the same target, each with different offsets. This enables scenarios like over-the-shoulder cameras, cinematic angles, or multiple viewpoints on the same character.

When the first FollowCamera attaches to a target, a TransitionCamera is automatically created for that target to enable seamless switching between cameras.

const manager = CameraManager.getInstance();

// Create main camera
const mainCam = manager.createFollowCamera();
mainCam.attach(player, { x: 0, y: 0, z: 0 });
mainCam.setAsViewEye();

// Create left shoulder camera
const leftCam = manager.createFollowCamera();
leftCam.attach(player, { x: -50, y: -20, z: 0 });

// Switch to left shoulder (smooth transition)
leftCam.setAsViewEye();

Hierarchy (View Summary)

Constructors

  • Creates a new FollowCamera instance

    Parameters

    • pId: string

      Unique identifier

    • pDiob: any

      VYLO Diob object

    • pManager: any

      Reference to the CameraManager

    Returns FollowCamera

Properties

bounds: { maxX: number; maxY: number; minX: number; minY: number }

Camera position bounds (Infinity = no limit)

cachedCameraPos: Vector2D

Cached camera position to avoid object churn

cachedGizmoPos: Vector2D

Cached gizmo position to avoid object churn

cachedTransitionPos: Vector2D

Cached transition position to avoid object churn

diob: any

VYLO Diob object representing the camera

gizmoColor: number

Color used for gizmo visualization (hex value)

gizmoLineLength: number

The length of the gizmo line

id: string

Unique identifier for this camera instance

isViewEye: boolean

Whether this camera is currently the active view eye

manager: CameraManager

Reference to the CameraManager that owns this camera

operationIgnoreTimeScale: boolean

If true, this action ignores all time scale (global and camera)

operationTimeScale: null | number

Per-action override time scale (temporary), null when not set

owner: null | GameInstance | Vector2D

The owner/target this camera belongs to (GameInstance or Vector2D) This represents who the camera is attached to or following

position: Vector2D

Current position of the camera in world space

previousPosition: Vector2D

Previous position of the camera in world space (used for velocity tracking)

randomGizmoAngle: number

The random angle for the gizmo

timeScale: number

Camera-specific time scale multiplier (1.0 = normal)

trackTargetZ: boolean

Whether to track the target's Z position and subtract it from the Y position. Enabled by default. Useful for 2.5D isometric-style games where height (Z) affects screen Y.

transitionDurationX: number

Transition duration for X axis in milliseconds

transitionDurationY: number

Transition duration for Y axis in milliseconds

transitionEaseX: EaseType

Easing function for X axis transitions

transitionEaseY: EaseType

Easing function for Y axis transitions

transitioning: boolean

Whether this camera is currently transitioning to become the view eye

transitionProgress: number

Transition progress (0-1) when becoming view eye

transitionStartPos: Vector2D

Starting position for transitions

transitionTargetPos: Vector2D

Target position for transitions

transitionTime: number

Elapsed time for current transition

Camera type identifier

velocity: Vector2D

Current velocity of the camera in pixels per second

Accessors

  • get gizmoEnabled(): boolean
  • Getter for gizmoEnabled property

    Returns boolean

  • set gizmoEnabled(value: boolean): void
  • Setter for gizmoEnabled property that notifies CameraManager

    Parameters

    • value: boolean

    Returns void

  • get isActive(): boolean
  • Getter for isActive property

    Returns boolean

  • set isActive(value: boolean): void
  • Setter for isActive property that notifies CameraManager

    Parameters

    • value: boolean

    Returns void

  • get trackViewEyeZ(): boolean
  • Whether to track the view eye's Z position (alias for trackTargetZ)

    Returns boolean

  • set trackViewEyeZ(pValue: boolean): void
  • Parameters

    • pValue: boolean

    Returns void

Methods

  • Activates this camera, enabling updates

    Returns void

  • Applies global time scale to delta time for this camera

    Parameters

    • pDeltaTime: number

      Raw delta time

    Returns number

    Scaled delta time

  • Attaches this camera to a target with optional offsets.

    The camera will continuously follow the target's position plus the specified offsets, regardless of whether this camera is the active view eye or not. This ensures all cameras stay synchronized with their targets for seamless transitions. Multiple cameras can attach to the same target with different offsets.

    Parameters

    • pTarget: GameInstance | Vector2D

      GameInstance or Vector2D to follow

    • OptionalpOffsets: Partial<CameraOffset>

      Optional offsets from target position (defaults to {0, 0, 0}) Z-offset is applied as negative Y offset for depth effect

    • OptionalpOptions: Partial<FollowCameraOptions>

    Returns void

    // Attach to player at center
    camera.attach(player);

    // Attach with left shoulder offset
    camera.attach(player, { x: -50, y: -20, z: 0 });

    // Attach with forward depth offset (positive Z moves camera "up" in 2D)
    camera.attach(player, { x: 0, y: 0, z: 30 });

    // Attach to static position
    camera.attach({ x: 100, y: 200 });
  • Clamps camera position to bounds

    Returns void

  • Clears all camera bounds

    Returns void

    // Remove all bounds restrictions
    camera.clearBounds();
  • Deactivates this camera, disabling updates

    Returns void

  • Destroys this camera and cleans up resources

    Returns void

  • Gets the position where gizmos should be drawn for this camera

    Returns Vector2D

    Position for gizmo drawing (reuses cached object to avoid churn)

  • Gets the current camera offsets from the target.

    Returns Readonly<CameraOffset>

    Readonly offsets object with x, y, and z

  • Gets the current target being followed

    Returns null | GameInstance | Vector2D

    The target or null if not attached

  • Gets the Z value of a target if trackTargetZ is enabled, else returns 0. Used to subtract target height from Y position for 2.5D depth effects.

    Parameters

    Returns number

    The target's z value, or 0 if tracking is disabled or target has no z

  • Gets this camera's time scale

    Returns number

  • Gets the current transition position

    Returns Vector2D

    Interpolated position based on transition progress

  • Gets the true camera position for a target (GameInstance or Vector2D) For GameInstance: returns center position (where camera should be) For Vector2D: returns the position directly Reuses cached object to avoid churn

    Parameters

    Returns Vector2D

  • Disables gizmo visualization for this camera

    Returns void

  • Checks if this camera is currently attached to a target

    Returns boolean

    True if attached, false otherwise

  • Checks if a target is a Vector2D (has x, y properties but no mapName)

    Parameters

    Returns pTarget is Vector2D

    True if target is Vector2D, false if GameInstance

  • Called when this camera is no longer the active view eye. Can be overridden by subclasses to pause or clean up operations.

    Returns void

  • Removes this camera from being the view eye and falls back to VYLO.Client.mob

    This is useful when you want to stop using a camera but keep it alive for potential future use. The camera will continue following its target but won't be the active view eye.

    Returns void

    // Stop using this camera but keep it following
    followCamera.removeViewEye(); // Falls back to VYLO.Client.mob
  • Resets this camera's time scale to 1.0

    Returns void

  • Resets ongoing transitions when time scale changes

    Returns void

  • Sets camera position bounds (Infinity = no limit in that direction)

    Parameters

    • pMinX: number

      Minimum X position (use -Infinity for no limit)

    • pMaxX: number

      Maximum X position (use Infinity for no limit)

    • pMinY: number

      Minimum Y position (use -Infinity for no limit)

    • pMaxY: number

      Maximum Y position (use Infinity for no limit)

    Returns void

    // Clamp camera to a 1000x1000 area starting at (0,0)
    camera.setBounds(0, 1000, 0, 1000);

    // Only clamp X axis, Y is free
    camera.setBounds(0, 1000, -Infinity, Infinity);
  • Updates the camera's offsets from the target.

    Useful for dynamic camera adjustments like aiming or crouching.

    Parameters

    • pX: number

      X-axis offset

    • pY: number

      Y-axis offset

    • pZ: number

      Z-axis offset (applied as negative Y offset for depth effect)

    Returns void

    // Shift camera right when aiming
    camera.setOffsets(30, 0, 0);

    // Move camera up and forward (positive Z reduces Y position)
    camera.setOffsets(0, -10, 20);

    // Reset to center
    camera.setOffsets(0, 0, 0);
  • Sets the owner/target this camera belongs to

    Parameters

    Returns void

  • Sets transition settings for smooth camera switching

    Parameters

    Returns void

    // Single duration and ease for both axes
    camera.setSettings({ duration: 500, ease: 'easeInOutCubic' });

    // Separate settings for each axis
    camera.setSettings({
    duration: { x: 300, y: 500 },
    ease: { x: 'easeOutCubic', y: 'easeInOutCubic' }
    });
  • Sets the smooth following behavior

    Parameters

    • pEnabled: boolean

      Whether smooth following is enabled

    Returns void

    // Enable smooth following with custom settings
    camera.setSmoothFollowing(true);

    // Disable smooth following (instant snap)
    camera.setSmoothFollowing(false);
  • Sets this camera's time scale

    Parameters

    • pScale: number

    Returns void

  • Sets whether the camera should track the target's Z position (subtracted from Y)

    Parameters

    • pEnabled: boolean

      Whether tracking is enabled

    Returns void

  • Sets whether the camera should track the view eye's Z position (alias for setTrackTargetZ)

    Parameters

    • pEnabled: boolean

      Whether tracking is enabled

    Returns void

  • Enables gizmo visualization for this camera. A colored dot will be drawn at the camera's position for debugging.

    Returns void

  • Update method called each frame by CameraManager

    Parameters

    • pDeltaTime: number

      Time elapsed since last update in milliseconds

    Returns void

  • Updates the camera's diob position with proper view eye offset This is the same for all cameras - they all need to offset the diob to center the target on screen

    Returns void

  • Updates the transition progress

    Parameters

    • pDeltaTime: number

      Time elapsed since last update in milliseconds

    Returns boolean

    True if transition is complete

  • Updates the camera's velocity based on elapsed time and position change.

    Parameters

    • pDeltaTime: number

      Elapsed time in milliseconds

    Returns void