O'Reilly logo

Programming Game AI by Example by Mat Buckland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

or bustling close-knit herds of sheep. I’ve even managed to produce dense
flocks of hundreds of tiny particles that are reminiscent of jellyfish. As this
behavior is better seen than described, I recommend you open up the demo
executable and play around for a while. Beware though — flocking is
addictive! (Maybe that’s why some animals like to do it so much…) You
can adjust the influence of each behavior with the “A/Z,” “S/X,” and
“D/C” keys. In addition you can view the neighbors of one of the agents by
pressing the “G” key.
Ü
INTERESTING FACT Steering behaviors are often used to create special
effects for films. The first film to use the flocking behavior was Batman Returns,
where you can see flocks of bats and herds of penguins. The most recent films
to use steering behaviors are The Lord of the Rings trilogy, directed by Peter
Jackson. The movement of the orc armies in those films is created using steering
behaviors via a piece of software called Massive.
Now that you’ve seen the benefits, let’s take a look at exactly how steering
behaviors can be combined.
Combining Steering Behaviors
Often you will be using a combination of steering behaviors to get the
behavior you desire. Very rarely will you only use one behavior in isola-
tion. For example, you might like to implement an FPS bot that will run
fromAtoB(path following) while avoiding any other bots (separation)
and walls (wall avoidance) that may try to impede its progress (see Chap-
ter 7, “Raven: An Overview”). Or you might want the sheep you’ve
implemented as a food resource in your RTS game to flock together (flock
-
ing) while simultaneously wandering around the environment (wander),
avoiding trees (obstacle avoidance), and scattering (evade) whenever a
human or dog comes near.
All the steering behaviors described in this chapter are methods of one
class:
SteeringBehaviors.AVehicle owns an instance of this class and
activates/deactivates the various behaviors by switching them on and off
using accessor methods. For example, to set up one of the sheep for the sit
-
uation described in the previous paragraph, you may do something like this
(assuming a dog-like agent has already been created):
Vehicle* Sheep = new Vehicle();
Sheep->Steering()->SeparationOn();
Sheep->Steering()->AlignmentOn();
Sheep->Steering()->CohesionOn();
Sheep->Steering()->ObstacleAvoidanceOn();
Sheep->Steering()->WanderOn();
Sheep->Steering()->EvadeOn(Dog);
And from now on the sheep will look after itself! (You may have to shear it
in the summer though.)
How to Create Autonomously Moving Game Agents | 119
Combining Steering Behaviors

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required