Implementing the Pathfinder
One of the coolest features of an RTS game is that the selected units always find the best path to reach their destination, avoiding rocks, trees, buildings, and everything else on their way. There is an AI algorithm behind this feature, called a pathfinder, and it has a few different implementations. In this chapter, we will take a look at the most used algorithms and will focus on the Navigation Mesh (NavMesh).
We will implement the NavMesh on Unity by using the AI Navigation package, setting up our units as agents and the level items as obstacles, and letting the NavMesh find the best path and move the selected units to the destination, avoiding or moving around the obstacles. We are also going to learn how to use the visual debugging tool from the AI Navigation package to see in real time how the NavMesh finds the best path for the agents.
By the end of this chapter, you will learn what a pathfinder algorithm is and the difference between the most...