Book Image

Unity AI Programming Essentials

By : Curtis Bennett
Book Image

Unity AI Programming Essentials

By: Curtis Bennett

Overview of this book

Table of Contents (19 chapters)

The behavior tree demo


Now that we know about the different nodes we can use, we'll create a demo that shows how to use the action and decision nodes. The demo will show how to have a character perform multiple tasks. We will have an entity, an enemy spaceship, patrolling an area, but only for a given amount of time; then, the ship will return to its home base. The steps for this example might seem overly complicated and we could do a similar AI ourselves without behavior trees with a simple script by hardcoding the different states. However, remember that behavior trees are easily extendible and scalable. With this demo, instead of two behaviors, we could take time to create a more complex character, going up to about 30 behaviors easily, but extending a script to do that would be pretty complicated and hard to maintain.

The start of this is similar to the pathfinding and patrol RAIN demos, except we will use a spaceship model instead of a walking character. You'll need to create a simple...