Talos docs

CastOptions

Since 0.6

Options for {@link WorldQuery.raycast} and {@link WorldQuery.shapeCast}.

Plain text

Signature

export interface CastOptions {
  /** Whether trigger volumes (`isTrigger` colliders) count as hits. Default true. */
  triggers?: boolean
  /**
   * What the cast passes straight through: an entity (handle or id) or a list. A camera probe that starts
   * at the player's head excludes the player, whose own capsule it would otherwise hit first. An id the
   * scene does not have excludes nothing.
   */
  exclude?: EntityHandle | string | (EntityHandle | string)[]
  /** Every entity carrying one of these tags is passed through as well: a tag or a list. */
  excludeTags?: string | string[]
  /**
   * Hit only colliders on these layers (names from the project's `layers`): a name or a list. The cast
   * passes through everything else. Absent: every layer. The collision matrix (`ignores`) does not apply to
   * a cast; only this option filters one. A name the project does not declare throws `physics.layer-unknown`.
   */
  layers?: string | string[]
}

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

Members

MemberSignatureDescription
triggerstriggers?: booleanWhether trigger volumes (isTrigger colliders) count as hits. Default true.
excludeexclude?: EntityHandle | string | (EntityHandle | string)[]What the cast passes straight through: an entity (handle or id) or a list. A camera probe that starts at the player's head excludes the player, whose own capsule it would otherwise hit first. An id the scene does not have excludes nothing.
excludeTagsexcludeTags?: string | string[]Every entity carrying one of these tags is passed through as well: a tag or a list.
layerslayers?: string | string[]Hit only colliders on these layers (names from the project's layers): a name or a list. The cast passes through everything else. Absent: every layer. The collision matrix (ignores) does not apply to a cast; only this option filters one. A name the project does not declare throws physics.layer-unknown.

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>