Note: Not being maintained by me, it was just an experiment for learning unity and c# concepts ((I may publish a complete package for this manner in future))
Dijkstra's Pathfinding Algorithm Unity Implementation.
It is the implementation of Dijkstra's Pathfinding Algorithm in Unity (Game Engine) that let's you find the shortest path between two Nodes in a Graph.
In this example we are going to find the shortest path from Node A to Node F:
In this example we will try to follow the path using a simple Cube object:
Follow one of the below ways to download the project:
- Clone (Run the below command in Terminal or Command Prompt)
git clone https://github.com/EmpireWorld/unity-dijkstras-pathfinding.git
Click on Graph object to use the Editor Integration.
You can use the Graph GetShortestPath method to get the shortest path and follow it:
Path path = myGraph.GetShortestPath ( start, end );
for ( int i = 0; i < path.nodes.Count; i++ ) {
Debug.Log ( path.nodes [i] );
}
Debug.LogFormat ( "Path Length: {0}", path.length );
Check the Follower Script for usage example.
MIT @ Hasan Bayat
Made with ❤️ by Hasan Bayat