PatrolIntent
new PatrolIntent()PatrolIntent - Waypoint patrol behavior
Patrols between waypoints in sequence, optionally looping. Low priority intent that activates when no threats are present.
Usage
Events Emitted
| Event | When | Payload |
|---|---|---|
patrol |
Patrol starts (intent activates) | { waypointIndex, waypoint } |
waypointReached |
Arrived at a waypoint | { waypointIndex, waypoint, isLast } |
body.ai.addEventListener('patrol', (event) => {
console.log('Started patrolling at waypoint', event.waypointIndex);
});
body.ai.addEventListener('waypointReached', (event) => {
console.log('Arrived at waypoint', event.waypointIndex);
});
Example
body.ai.addIntent(new PatrolIntent({
waypoints: [
{ x: 0, y: 0, z: 0 },
{ x: 10, y: 0, z: 0 },
{ x: 10, y: 0, z: 10 },
{ x: 0, y: 0, z: 10 }
],
waitTime: 2.0, // Wait at each waypoint
loop: true, // Loop back to start
priority: 20 // Low priority
}));
Properties
# .events : Array.
Events this intent can emit.
# .waypoints :
Get waypoints.
# .waypoints :
Set waypoints.
Methods
canActivate#
canActivate(state : State, memory : Memory) : booleanCheck if patrol can activate. Activates when there's no visible target.
Parameters
Returns
boolean — True if can activate.update#
update(body : Object, state : State, memory : Memory, delta : number) : AgentIntentUpdate patrol behavior.
Parameters
Returns
AgentIntent — Action instructions.onActivate#
onActivate(state : State, memory : Memory)Called when patrol activates.
Parameters
set#
set(config : Object) : PatrolIntentConfigure patrol parameters.
Parameters
configObjectConfiguration object.
Returns
PatrolIntent — This instance for chaining.serialize#
serialize() : ObjectSerialize intent configuration for worker transfer.
Returns
Object — Serialized configuration.reset#
reset()Reset patrol state.