This is a demonstration of pathfollowing, where I have created a 30 X 30 grid on which I perform pathfinding through A* algorithm. This is a build-up on my last project, pathfinding. You can find it here. I have made this is Unity 5, you can find the code here at GitHub.
In pathfollowing I do all the things as I do in the pathfinding project, the only difference being that allow for diagonal neighbours too, provided they arent a wall node. I have 10 actors moving around, following their own path. I also have a visualize toggle button in for debugging purposes, where you can see the path of the actor and its steering vector.
This is built-up over the pathfinding project, with some differences. First, there is terrain data present, which means the when the actor walks over forest, road or water his speed varies. He walks fastest or road, slow on forest and slowest on water. Secondly, diagonal nodes are considered as neighbours, hence ‘diagonal manhattan’ distance is in play.
Here I assign the start and end nodes randomly to each player.
Based on the start and end nodes, I find a path. Then I trace the path in TracePath() function.
I calculated the path if it isnt already calculated, or if the actor has reached the destination.