Programming‎ > ‎

AI Basics

Entity
Every AI should have the component AIEntity. It acts as a generic container holding references to all AIPart instances.

Parts
Parts can be looked at as body parts or functionality pieces of an AI entity. Every part has a tick method that is to be called by the AI controller. Examples of body parts include:
  • AIBody: Stores body information like radius or height and updates the current position and view direction.
  • AILocomotion: Stores information like movement or turn speed and moves the entity.
  • AISense: Stores information like view distance or field of view and updates lists of surrounding interests, dangers and obstacles.
  • AISteering: Calculates a movement direction from the target direction, avoiding obstacles and dangers along the way.
All parts are completely generic and suitable for any AI type we might add.

Controller
Inherits the Behave behaviour tree blueprint of a certain AI type and implements all methods that are called by the behaviour tree. The controller is also responsible for ticking both Behave and the AI parts.

Every AI type should generally have its own controller class and behaviour tree. More info on how to setup a new controller can be found on the AI Controller page.

Obstacle Avoidance
AI steering is done by a fairly customized implementation of context behaviours, which themselves are a modified version of steering behaviours. They are used to wage interests, dangers and obstacles in a way that interests are seeked while obstacles and dangers are avoided such that the AI's face isn't violently smashed into a wall.

Target selection is not part of the context behaviours used for steering and is instead done in the controller since it is more flexible that way.

Behaviour Trees
We use Behave to structure and implement behaviour trees. I think the official documentation explains their usage better than I ever could, so I won't attempt to do so.

Behaviours
Since behaviour trees are highly modular it makes sense to create subtrees for any common behaviours to structure the flow and keep the main behaviour tree of the AI type nice and clean. To implement actions of a dedicated subtrees we're using a behaviour system that forward declares action handlers of a complete subtree.
Comments