Chapter 2. Chasing and Evading
In this chapter we focus on the ubiquitous problem of chasing and evading. Whether you’re developing a spaceship shooter, a strategy simulation, or a role-playing game, chances are you will be faced with trying to make your game’s nonplayer characters either chase down or run from your player character. In an action or arcade game the situation might involve having enemy spaceships track and engage the player’s ship. In an adventure role-playing game it might involve having a troll or some other lovely creature chase down your player’s character. In first-person shooters and flight simulations you might have to make guided missiles track and strike the player or his aircraft. In any case, you need some logic that enables nonplayer character predators to chase, and their prey to run.
The chasing/evading problem consists of two parts. The first part involves the decision to initiate a chase or to evade. The second part involves effecting the chase or evasion—that is, getting your predator to the prey, or having the prey get as far from the predator as possible without getting caught. In a sense, one could argue that the chasing/evading problem contains a third element: obstacle avoidance. Having to avoid obstacles while chasing or evading definitely complicates matters, making the algorithms more difficult to program. Although we don’t cover obstacle avoidance in this chapter, we will come back to it in Chapters 5 and 6. In this chapter we focus on the ...
Get AI for Game Developers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.