Talos docs

VehicleLanding

Since 0.7

{@link Vehicle.landing}: the last touchdown.

Plain text

Watch count change to play a landing effect, sound or camera bump in one line. ts // A thump scaled by how hard it came down. update(ctx) { const l = ctx.vehicle?.landing if (l && l.count !== this.seen) { this.seen = l.count if (l.fallSpeed > 3) ctx.log("thump", l.fallSpeed) } }

Signature

export interface VehicleLanding {
  /** Touchdowns so far: goes up by one each time all wheels were off the ground and one comes down. */
  readonly count: number
  /** The fastest downward speed of that flight, m/s, 0 or more. */
  readonly fallSpeed: number
  /** How long that flight lasted, seconds. */
  readonly airTime: number
}

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

Members

MemberSignatureDescription
countreadonly count: numberTouchdowns so far: goes up by one each time all wheels were off the ground and one comes down.
fallSpeedreadonly fallSpeed: numberThe fastest downward speed of that flight, m/s, 0 or more.
airTimereadonly airTime: numberHow long that flight lasted, seconds.

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>