A* Pathfinding
Next up, we'll implement the A* algorithm in a Unity environment using C#. The A* Pathfinding algorithm is widely used in games and interactive applications even though there are other algorithms, such as Dijkstra's algorithm, because of its simplicity and effectiveness. We've briefly covered this algorithm previously, in Chapter 1, The Basics of AI in Games, but let's review the algorithm again from an implementation perspective.
Revisiting the A* algorithm
We briefly touched on the A* algorithm earlier in the book, so let's review the basics before we dive into our implementation. For starters, we need to create a grid-based representation of our map. The best option for this is a 2D array. This grid and all of its associated data will be contained in our GridManager
class. The GridManager
class will contain a list of Node
objects that represent each cell in our grid. The nodes themselves will contain some additional data about themselves, such as their heuristic cost and...