Displaying path from pointgraph in the scene

I am using the point graph system, and i’m curious as to how i would go about adding a line that correctly depicts the shortest path between two nodes in said point graph. I’m aware that i should use the line renderer, although i’m not sure where/how to add script to accomplish this.

Thanks,

Does anyone know how to render lines from node to node?

Hi

You can use the Unity LineRenderer to draw lines. It should be relatively straight forward to get the path on the callback and then simply assign the points to a LineRenderer.
If you have the pro version, the example scene PathTypes does just that.

Something like this:

public void OnPathComplete (Path p) { List<Vector3> path = p.vectorPath; lineRenderer.SetVertexCount (path.Count); for (int i=0;i<path.Count;i++) lineRenderer.SetPosition (i, path[i]); }

I’m not too keen on c# code and transcribing it to javascript. Could you possibly give the javascript code for this? Thanks!

And would it be possible to reference the last path completed and only use that path to render?

Hi

If you use that code, it would replace the contents of the line renderer every time a path is completed, so it will always show the last path.

I’m not too good at javascript, but I will try:

`
var lineRenderer : LineRenderer;

function OnPathComplete (p : Path) {
List path = p.vectorPath;
lineRenderer.SetVertexCount (path.Count);
for (var i = 0;i < path.Count; i++) {
lineRenderer.SetPosition (i, path[i]);
}
}`

I think something like this is closer. Import the lib for lists.

import System.Collections.Generic;

then try this

var drawpath : List.<Vector3> = p.vectorPath; var lineRenderer : LineRenderer = gameObject.AddComponent(LineRenderer); lineRenderer.SetVertexCount (drawpath.Count); for (var i = 0;i < drawpath.Count; i++) { lineRenderer.SetPosition (i, drawpath[i]); }