AIPatrolComponent - acrimi/Raven GitHub Wiki

Holds the state for simple patrol behavior where the entity will move, stop, and change direction at random, bounded intervals. The patrol route can be optionally bounded to a specific perimeter so that the entity will not leave the area, and will continuously move toward it if they somehow end up outside of bounds. The movement logic will do its best to avoid collision objects if the entity has collision enabled via its CollisionComponent, and can be optionally expanded to avoid certain terrain types as well.

Configuration

When used inside the components block, the initial state of the component can be configured with the following parameters:

Key Type Description
minIdleTime float The minimum amount of time, in seconds, that the entity needs to be idle before an attempt to move can be made. Defaults to 1s.
minDirectionTime float The minimum amount of time, in seconds, that the entity needs to be moving in a given direction before an attempt to either change directions or stop moving can be made. Defaults to 1s.
maxBlockedTime float The maximum amount of time, in seconds, that the entity's path of movement can be blocked, before forcing an attempt to change direction or stop moving. Overrides minDirectionTime. Defaults to 1s.
currentDirectionLookahead float Forward distance to check for obstacles while moving. If a collision object or terrain is detected, or if the current movement would lead out of the patrol perimeter, an attempt to change direction or stop will be forced. Defaults to 1/2 the entity's size along the axis of movement.
changeDirectionLookahead float Distance to check for obstacles when attempting to change movement direction. If a direction would lead to a collision or terrain, or if it would lead out of the patrol perimeter, that direction be prevented from being chosen. Defaults to the entity's size along the axis of the direction being tested.
terrainBlacklist string[] Optional list of terrain types that should be avoided during patrol
terrainWhitelist string[] Optional list of terrain types that the entity will be restricted to during patrol. If empty, all terrain types will be considered to be allowed.
perimeter object Optional bounding box to limit area of patrol movement
      width float The width of the patrol perimeter
      height float The height of the patrol perimeter
      centered boolean If true, the perimeter will be centered on the entity's spawn position. Defaults to false.
      x float The left position of the patrol perimeter. Ignored if centered is true.
      y float The bottom position of the patrol perimeter. Ignored if centered is true.

Examples:

"AIPatrolComponent": {
  "minIdleTime": 1,
  "minDirectionTime": 0.5,
  "maxBlockedTime": 0.5,
  "currentDirectionLookahead": 16,
  "changeDirectionLookahead": 32,
  "terrainBlacklist": [
    "water",
    "lava"
  ],
  "perimeter": {
    "width": 160,
    "height": 160,
    "centered": true
  }
}
"AIPatrolComponent": {
  "minIdleTime": 0,
  "terrainWhitelist": [
    "ground"
  ],
  "perimeter": {
    "width": 160,
    "height": 160,
    "x": 128,
    "y": 64
  }
}

Properties

This component has no exposed properties