EngageIntent

@three-blocks/proAIIntentCombatShootingEvents
new EngageIntent()
Extends
Intent

EngageIntent - Combat engagement behavior

Attacks visible targets with shooting and optional movement. High priority intent that activates when targets are detected.

Usage

Events Emitted

Event When Payload
engage Combat starts (intent activates) { targetPosition, targetDistance }
fire Weapon fires { origin, direction, target }
body.ai.addEventListener('engage', (event) => {
  console.log('Engaging at distance:', event.targetDistance);
});

body.ai.addEventListener('fire', (event) => {
  createMuzzleFlash(event.origin);
  playSound('gunshot');
});
Example
body.ai.addIntent(new EngageIntent({
  fireRate: 2.0,       // Shots per second
  engageRange: 25,     // Max engagement distance
  optimalRange: 15,    // Preferred combat distance
  strafeEnabled: true, // Strafe during combat
  priority: 80         // High priority
}));

Properties

.events : Array.

Events this intent can emit.

.fireRate :

Get fire rate.

.fireRate :

Set fire rate.

Methods

canActivate#

canActivate(state : State, memory : Memory) : boolean

Check if engage can activate. Activates when a target is visible within range.

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 engagement behavior.

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

onActivate#

onActivate(state : State, memory : Memory)

Called when engagement activates.

Parameters
Current perception state.
Time-decaying memory.

set#

set(config : Object) : EngageIntent

Configure engagement parameters.

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

serialize#

serialize() : Object

Serialize intent configuration for worker transfer.

Returns
Object — Serialized configuration.