Wander Behavior with Apex Path and Apex Utility AI
This document is a part of a series of tutorial documents for getting started with the Apex Utility AI using Apex Path.
The purpose of this document is to provide a description to the classes used in the scene “AI_Demo_8”, as well as a tutorial on how to create a Apex Utility AI has a wander behaviour.
Creating a Wander Action
We start by making a Wander Action class. We use the Apex Utility AI IRequireTermination interface. This forces us to implement the Terminate method, which will be called once the AI changes the action being executed. This method is useful for causing the Unit to stop wandering, instead of having one Action for starting and another one for stopping. To make it easier to see whether the Unit is supposed to wander or not, we change its color as well: Green for when it is supposed to wander and red when it is not. The action class with both of its relevant methods can be seen in the code snippet below.
public sealed class Wander : ActionBase<WanderContext>, IRequireTermination
[ApexSerialization(defaultValue = 5f), FriendlyName("Radius", "The radius in which the AI will wander")]
public float radius = 5f;
[ApexSerialization(defaultValue = 2.5f), FriendlyName("Minimum Distance", "The minimum distance the AI will wander")]
public float minimumDistance = 2.5f;
[ApexSerialization(defaultValue = 1f), FriendlyName("Seconds to Linger", "How many seconds to linger at each destination before moving on")]
public float lingerForSeconds = 1f;
public override void Execute(WanderContext context)
// Tell the Unit to start wandering
WanderMaster.Wander(context.unitFacade, radius, minimumDistance, lingerForSeconds);
context.isWandering = true;
// Set the color of the Unit to green
context.renderer.material.color = Color.green;
// This method will be called once the AI changes action
public void Terminate(IAIContext c)
var context = (WanderContext)c;
// Tell the Unit to stop wandering
context.isWandering = false;
// Set the color of the Unit to red
context.renderer.material.color = Color.red;
The screenshot below shows the unit wandering with Apex Path visualization on.