Talos docs

Junction

Since next

What {@link World.junction} reads: where roads meet, as the load built it.

Plain text

Signature

export interface Junction {
  /** The middle of its arms, world space. */
  readonly centre: [number, number, number]
  /** Per arm, how far along it (from where the road meets the junction) the junction's surface ends: where that road should end. */
  readonly mouthsM: number[]
  /** A stop line across each arm's lane in: from the centreline to the lane's edge, world space. */
  readonly stopLines: { arm: number; from: [number, number, number]; to: [number, number, number] }[]
  /** Every path through it: from an arm's lane in to another arm's lane out, evenly spaced points from mouth to mouth, and its length in metres. */
  readonly lanes: { from: number; to: number; turn: "straight" | "left" | "right"; points: [number, number, number][]; lengthM: number }[]
}

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

Members

MemberSignatureDescription
centrereadonly centre: [number, number, number]The middle of its arms, world space.
mouthsMreadonly mouthsM: number[]Per arm, how far along it (from where the road meets the junction) the junction's surface ends: where that road should end.
stopLinesreadonly stopLines: { arm: number; from: [number, number, number]; to: [number, number, number] }[]A stop line across each arm's lane in: from the centreline to the lane's edge, world space.
lanesreadonly lanes: { from: number; to: number; turn: "straight" | "left" | "right"; points: [number, number, number][]; lengthM: number }[]Every path through it: from an arm's lane in to another arm's lane out, evenly spaced points from mouth to mouth, and its length in metres.

Example

The tested fixture fixtures/host/road-edges.ts.

// A behavior that keeps a car inside the road's wall: what `ctx.world.road(id).edge(s)` is for.
import type { Behavior } from "@argus/api"

export default {
  update(ctx) {
    const road = ctx.world.road("track")
    if (road === null) return
    const here = road.closest(ctx.entity.position)
    const edge = road.edge(here.s)
    // Keep the car's centre a radius inside the wall's inner face, or the kerb's edge when there is no wall.
    const limit = (edge.barrier?.inner ?? edge.kerbOuter) - 0.8
    const over: number = Math.abs(here.offset) - limit
    const wallHeight: number | undefined = road.barrier?.heightM
    const sides: "left" | "right" | "both" | undefined = road.barrier?.sides
    const kerb: number = road.kerbWidth + road.kerbHeight
    ctx.state.over = [over, wallHeight, sides, kerb, edge.halfWidth, edge.barrier?.left, edge.barrier?.right, edge.barrier?.outer, edge.barrier?.height]
  },
} satisfies Behavior