Game Development Reference
In-Depth Information
Chapter 3. Behavior Trees
When creating AI for game characters, we want them to appear to behave in realistic
ways. This is done by defining different behaviors that a character can do, such as
walking, patrolling, attacking, or searching for something, as well as how the char-
acter reacts to different items or events in the game environment. In addition to de-
fining a character's behaviors, we need to define when the different behaviors occur.
For example, instead of just following a path, we might want the character to change
behaviors at different times. This chapter will look at the most popular way to define
behaviors and when they occur: behavior trees. We have already looked at behavior
trees in the previous chapters, but here, we will go into more detail.
In this chapter, we will learn about:
• How behavior trees work
• Implementing complex behavior trees
• RAIN's behavior trees and the different options that we have to configure them
• Setting up more advanced behavior trees with a character that has multiple
objectives
An overview of behavior trees
For game AI, we need to define logic for the different AI entity characters in the game,
that is, how they will act and react to different things in the game environment. The
traditional and simpler way to do this is to use Finite State Machines ( FSMs ). In
this approach, each character can be in a distinct state, and an FSM is a graph that
defines states (nodes) and their transitions (edges). A simple example would be an
enemy entity with two states, patrol and attack. The FSM will start in a patrol state,
and when it gets close to a player, it transitions to an attack state. FSMs work for very
simple state setups such as this, but they don't scale well, as the states and trans-
itions have to be manually configured, usually through code. What if instead of the
two states, our enemy character was more realistic and had 10 or even 100 different
states, with many transitions between each? This becomes very difficult to manage
and implement.
The popular alternative to FSMs is behavior trees. Behavior trees are a different way
to define logic for characters that scale easily to having many states. Instead of de-
Search WWH ::




Custom Search