NavAgent
Since 0.6
Present on ctx.nav when the entity has a nav-agent component.
Steering itself runs in Rust.
Reached in a behaviour as ctx.nav.
Signature
export interface NavAgent {
/** Start moving toward `target` along the navmesh at `speed` m/s (the agent's default when omitted). */
goTo(target: Target, speed?: number): void
stop(): void
/** True once within the agent's arrival radius of the target. */
readonly arrived: boolean
/** True when the agent has made no progress for a while; the playtester reports this. */
readonly stuck: boolean
readonly target: Vec3 | null
}
Import: import type { NavAgent } from "@argus/api"
Members
| Member | Signature | Description |
|---|---|---|
goTo | goTo(target: Target, speed?: number): void | Start moving toward target along the navmesh at speed m/s (the agent's default when omitted). |
stop | stop(): void | |
arrived | readonly arrived: boolean | True once within the agent's arrival radius of the target. |
stuck | readonly stuck: boolean | True when the agent has made no progress for a while; the playtester reports this. |
target | readonly target: Vec3 | null |
Example
The tested fixture fixtures/app/agent.ts.
import type { Behavior } from "@argus/api"
// Sends a nav agent to `props.target` once, then reports arrival through ctx.state so the
// test can read it without polling the crowd directly.
export default {
init(ctx) {
ctx.state.arrived = false
ctx.nav?.goTo(ctx.props.target as [number, number, number])
},
update(ctx) {
if (ctx.nav?.arrived) ctx.state.arrived = true
},
} satisfies Behavior