Skip to content

Latest commit

 

History

History
38 lines (27 loc) · 1.29 KB

File metadata and controls

38 lines (27 loc) · 1.29 KB

UnityAStarPathfinding

Shortest path finding with A* algorithm for Unity.

Ekran Görüntüsü (21) Ekran Görüntüsü (22)

Usage (On example 3D human mesh)

List<Node> nodes = new List<Node>(); //create nodes list to store nodes on the scene
List<Edge> edges = new List<Edge>();  //create edges list to store edges on the scene 
// follows basic (NODE - EDGE - NODE) structure

 for (int i = 0; i < vertices.Length; i++) //add vertices to the nodes list
 {
     Vector3 point = transform.TransformPoint(vertices[i]);
     var node = new Node(point, i);
     this.nodes.Add(node);
 }

//add connections between vertices to the edges list
//...
//...
//...

//Use PathFinder3000's method to find the path.
PathFinder3000.Search(this.ALL_NODES[vertexIndex1], this.ALL_NODES[vertexIndex2]);
// (startingNode, destinationNode) as parameters.

//Visualize the path using a line renderer:
ShowThePath(PathFinder3000.Search(this.ALL_NODES[vertexIndex1], this.ALL_NODES[vertexIndex2]));

More information about the A* Algorithm:

https://en.wikipedia.org/wiki/A*_search_algorithm