PatrolIntent

@three-blocks/proAIIntentPatrolMovementEvents
new PatrolIntent()
Extends
Intent

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) : boolean

Check if patrol can activate. Activates when there's no visible target.

Parameters
Current perception state.
Time-decaying memory.
Returns
boolean — True if can activate.

update#

update(body : Object, state : State, memory : Memory, delta : number) : AgentIntent

Update patrol behavior.

Parameters
bodyObject
The physics body.
Current perception state.
Time-decaying memory.
deltanumber
Time delta in seconds.
Returns
AgentIntent — Action instructions.

set#

set(config : Object) : PatrolIntent

Configure patrol parameters.

Parameters
configObject
Configuration object.
Returns
PatrolIntent — This instance for chaining.

serialize#

serialize() : Object

Serialize intent configuration for worker transfer.

Returns
Object — Serialized configuration.

reset#

reset()

Reset patrol state.