Talos docs

CameraArm

Since 0.6

{@link CameraHandle.arm}: what the engine rig's boom is doing this frame.

Plain text

Signature

export interface CameraArm {
  /** True while a `third-person` or `orbit` rig resolved its arm this frame. Every number is 0 when false. */
  readonly active: boolean
  /** The length the rig asked for, metres: the `distance` of the last `set`. */
  readonly desired: number
  /** The length it has, pivot to eye, after collision and the recovery ease. */
  readonly length: number
  /** Shorter than the arm's minimum (0.5 m): the eye is in or against the character. */
  readonly collapsed: boolean
  /** Geometry is shortening the arm. */
  readonly blocked: boolean
  /** What is shortening it, or null. */
  readonly blocker: EntityHandle | null
  /** 0..1, how far the followed character is faded away (see `fadeStart`). */
  readonly fade: number
  /** Radius of the sphere the boom sweeps: `probeRadius`, widened so the near plane never enters a wall. */
  readonly probeRadius: number
}

Import: import type { CameraArm } from "@argus/api"

Members

MemberSignatureDescription
activereadonly active: booleanTrue while a third-person or orbit rig resolved its arm this frame. Every number is 0 when false.
desiredreadonly desired: numberThe length the rig asked for, metres: the distance of the last set.
lengthreadonly length: numberThe length it has, pivot to eye, after collision and the recovery ease.
collapsedreadonly collapsed: booleanShorter than the arm's minimum (0.5 m): the eye is in or against the character.
blockedreadonly blocked: booleanGeometry is shortening the arm.
blockerreadonly blocker: EntityHandle | nullWhat is shortening it, or null.
fadereadonly fade: number0..1, how far the followed character is faded away (see fadeStart).
probeRadiusreadonly probeRadius: numberRadius of the sphere the boom sweeps: probeRadius, widened so the near plane never enters a wall.

Example

The tested fixture fixtures/recipes/couch-coop/scenes/behaviors/couch.ts.

import type { Behavior } from "@argus/api"

/**
 * Two players on one keyboard, one screen split down the middle.
 *
 * The scene's `meta.players` (`max: 2`, `keyboard: "split"`) gives player 1 the keys on the left
 * half (WASD) and player 2 the right half (the arrows), and `spawn { for: "player", player: N }`
 * makes `p1` and `p2` theirs; the engine walks each one's controller from their own keys. This
 * behaviour does the rest: it seats player 2 and gives each player a view.
 *
 * Seating: `join: "script"` means only a script seats anyone. A lobby would wait for a press; this
 * seats the right half at once, which is also what lets a headless self-test drive player 2
 * (headless, no key or pad ever joins anyone).
 *
 * Both players home is a win: each pad emits `goal-reached` (`home.ts`), and this counts them.
 */
interface State {
  home: string[]
  won: boolean
  layout: string
  views: number
  seated: number
}

export default {
  init(ctx) {
    // No number is no seat: under `keyboard: "player"` (the default) the keyboard has no halves.
    if (ctx.players.count < 2 && typeof ctx.players.join("keyboard-right") !== "number") {
      throw new Error('player 2 was not seated: "keyboard-right" needs meta.players.keyboard "split"')
    }
    // View 1 is `ctx.camera`; view 2 has a rig of its own. Each follows its player from behind.
    ctx.views.setLayout("left-right")
    for (const [view, id] of [[1, "p1"], [2, "p2"]] as const) {
      ctx.views.set(view, "third-person", { distance: 6, yaw: 0, pitch: -15 })
      ctx.views.follow(view, id)
    }
    ctx.state.home = []
    ctx.state.won = false
    // Kept so a test can read what was set up.
    ctx.state.layout = ctx.views.layout
    ctx.state.views = ctx.views.count
    ctx.state.seated = ctx.players.count
    ctx.events.on("goal-reached", (event) => {
      const goal = (event.data as { goal?: string }).goal
      if (goal === undefined || ctx.state.home.includes(goal)) return
      ctx.state.home.push(goal)
      if (ctx.state.home.length === 2 && !ctx.state.won) {
        ctx.state.won = true
        ctx.events.emit("both-home", { home: ctx.state.home })
      }
    })
  },
} satisfies Behavior<State>