Game Development Reference
In-Depth Information
Combining the techniques
In this chapter, we will take both of the AI techniques and combine them to create a
great AI package. Our behavior tree will utilize finite state machines to run the indi-
vidual behaviors, creating a unique and complex AI system. This AI package can be
used for an enemy AI as well as a friendly AI.
Let's start scripting!
Now, let's begin scripting our AI! To start off, create a new C# file and name it
AI_Agent . Upon opening it, delete any functions within the main class, leaving it
empty. Just after the using statements, add this enum to the script:
public enum Behaviors {Idle, Guard, Combat,
Flee};
This enum will be used throughout our script to determine what behavior our AI is in.
Now let's add it to our class. It is time to declare our first variable:
public Behaviors aiBehaviors = Behaviors.Idle;
This variable, aiBehaviors , will be the deciding factor of what our AI does. Its main
purpose is to have its value checked and changed when needed. Let's create our
first function, which will utilize one of this variable's purposes:
void RunBehaviors()
{
switch(aiBehaviors)
{
case Behaviors.Idle:
RunIdleNode();
break;
case Behaviors.Guard:
RunGuardNode();
break;
case Behaviors.Combat:
Search WWH ::




Custom Search