 David
|
Apologies for the intro questions. I am currently experimenting with the free version of A* to see if it fulfills the needs for my project. It’s looking fantastic, but the one outstanding issue is that I need the game to show the player their possible paths, rather than have them be invisible nodes. How might I go about doing this?
|
 Aron Granberg
|
If you want to draw all the nodes in a List Graph, try adding a mesh renderer to the nodes.
To draw the connections is a bit trickier, but still quite simple. Check out the Line Renderer in the Unity docs.
You can get the connections by looping through the nodes in the List Graph like this:
//using Pathfinding; //At top of script
ListGraph graph = AstarPath.active.astarData.listGraph; //Shortcut to the first listgraph in the scene
for (int i=0;i < graph.nodes.Length;i++) {
Node node = graph.nodes[i];
for (int i=0;i < node.connections.Length;i++) {
Debug.DrawLine ((Vector3)node.position, (Vector3)node.connections[i].position,Color.blue);
//Works in the editor, but use Line Renderer in game.
//This will however loop through every pair of nodes two times (since it's an undirected graph)
//So you might want to keep track of which pairs of nodes you have rendered before
}
}
|
 David
|
Aron, your support is totally dreamy. Thanks for the quick response, I’ll give it a go tonight
|