Skip to content

Dijkstra's Pathfinding Algorithm Unity Implementation. (Not being maintained by me, it is just an experiment.)

License

Notifications You must be signed in to change notification settings

hasanbayatme/unity-dijkstras-pathfinding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unity Dijkstra's Pathfinding

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.

Dijkstra_Animation

In this example we are going to find the shortest path from Node A to Node F:

Sample 1

In this example we will try to follow the path using a simple Cube object:

Sample 2

Getting Started

Download

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

Usage

Editor Usage

Click on Graph object to use the Editor Integration.

Runtime Usage

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.

Resources

💬 Forum Thread

License

MIT @ Hasan Bayat

Made with ❤️ by Hasan Bayat