Game Development Reference
In-Depth Information
Chapter 1. Pathfinding
Probably the most useful game AI is pathfinding. Pathfinding is all about making your
way from one point to another while navigating around obstacles. Unity excels at link-
ing the worlds of designers and programmers. AI is no different, and we'll see how to
make simple pathfinding AIs without ever touching the code. Pathfinding is probably
the most common AI game task, and there are many Unity plugins for it. We will be
looking at three different ones.
In this chapter, you will learn:
• Working with pathfinding
• Applying pathfinding in Quick Path, React, and RAIN AI packages
• Behavior trees
• Applying characters to Character Controller
• Unity's NavMesh
An overview
Pathfinding is a way to get an object from point A to point B. Assuming that there are
no obstacles, the object can just be moved in the direction of the target. But the AI
part of it is all about navigating the obstacles.
A poor AI might try walking a Non-Player Character ( NPC ) directly to the target.
Then, if it is blocked, it randomly tries to go to the right or left to look for a space that
might help. The character can get caught in different areas and become permanently
stuck.
A better AI will walk an NPC in an intelligent way to a target, and will never get stuck
in different areas. To compute a good path for the NPC to walk, the AI system will use
a graph that represents the game level, and a graph search algorithm is used to find
the path. The industry-standard algorithm for pathfinding is A* ( A Star ), a quick graph
search algorithm that uses a cost function between nodes—in pathfinding usually the
distance—and the algorithm tries to minimize the overall cost (distance) of the path.
If you want to learn to code your own pathfinding AI, try A* because it is simple to
implement and has a lot of simple improvements that you can apply for your game's
needs.
Search WWH ::




Custom Search