VisionSensor

@three-blocks/proAISensorVisionPerceptionEvents
new VisionSensor()
Extends
Sensor

VisionSensor - BVH raycast-based vision cone

Detects visible targets within a field of view using BVH raycasts. Writes perception data to State for use by Intents.

State Keys Written

  • targetVisible - Whether any target is visible (boolean)
  • targetPosition - Position of nearest visible target ({ x, y, z } | null)
  • targetDistance - Distance to nearest visible target (number)
  • targetBodyIndex - Body index of nearest visible target (number | null)
  • visibleTargets - Array of all visible targets

Usage

Events Emitted

Event When Payload
targetAcquired Target becomes visible { targetIndex, targetType, distance, position }
targetLost Target no longer visible { lastPosition }
body.ai.addEventListener('targetAcquired', (event) => {
  console.log('Target spotted at distance:', event.distance);
});

body.ai.addEventListener('targetLost', (event) => {
  console.log('Lost target, last seen at:', event.lastPosition);
});
Example
body.ai.addSensor(new VisionSensor({
  fov: 90,           // Field of view in degrees
  range: 30,         // Maximum vision range
  rayCount: 5,       // Rays per scan
  targetTypes: ['dynamic'],  // Body types to detect
  updatePeriod: 0.1  // Update at 10 Hz
}));

Properties

.events : Array.

Events this sensor can emit.

.fov :

Get field of view.

.fov :

Set field of view.

.range :

Get vision range.

.range :

Set vision range.

Methods

set#

set(config : Object) : VisionSensor

Configure sensor parameters.

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

serialize#

serialize() : Object

Serialize sensor configuration for worker transfer.

Returns
Object — Serialized configuration.