Render ListGraph paths to game?

HomeForumsA* Pathfinding ProjectBeginner QuestionsRender ListGraph paths to game?

This topic has 2 voices, contains 2 replies, and was last updated by  David 101 days ago.

Viewing 3 posts - 1 through 3 (of 3 total)
Author Posts
Author Posts
February 7, 2012 at 03:36 #1441

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?

February 7, 2012 at 18:37 #1450

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
}
}

February 7, 2012 at 21:49 #1455

David

Aron, your support is totally dreamy. Thanks for the quick response, I’ll give it a go tonight :)

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: Render ListGraph paths to game?
Your information:






<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>