RoadBarrier
Since 0.6
A road's wall as its file asked for it: RoadLine.barrier.
Signature
export interface RoadBarrier {
/** Which sides have a wall. */
readonly sides: "left" | "right" | "both"
/** Wall height above the road surface (along the banked up axis), metres. */
readonly heightM: number
/** Wall thickness, metres. */
readonly thicknessM: number
/** Gap between the kerb's outer edge and the wall's inner face, metres (floored over, so it is an apron a car can drive on). */
readonly offsetM: number
/** Ranges of distance `[from, to]` along the road with no wall. */
readonly gapsAt: readonly (readonly [number, number])[]
}
Import: import type { RoadBarrier } from "@argus/api"
Members
| Member | Signature | Description |
|---|---|---|
sides | readonly sides: "left" | "right" | "both" | Which sides have a wall. |
heightM | readonly heightM: number | Wall height above the road surface (along the banked up axis), metres. |
thicknessM | readonly thicknessM: number | Wall thickness, metres. |
offsetM | readonly offsetM: number | Gap between the kerb's outer edge and the wall's inner face, metres (floored over, so it is an apron a car can drive on). |
gapsAt | readonly gapsAt: readonly (readonly [number, number])[] | Ranges of distance [from, to] along the road with no wall. |
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