# How to draw a NavMesh Path to a destination without traversing the path in Unity3d?

I have a set of pre-determined destinations. When the user chooses any one of those destinations, the path to the destination should be drawn, similiar to google maps. I am trying to do this in unity, but not able to figure out just how.

• Are you asking for the determination of the points in path also? Or just for the drawing part? I mean, have you managed to calculation of the traversal points for reaching to those destinations? – Tolga Şen Aug 31 '17 at 12:49
• I have used NavMesh.CalculatePath to determine the points in the path. Now, the drawing part is what I'm having trouble with. – azemda Aug 31 '17 at 13:07

You can use LineRenderer component that Unity provides. Attach it to the the appropriate GameObject, set the parameters of it in order to visualise the line however you desire and use the following code:

private Vector3[] wayPoints; //You have to set these waypoints before you start to use LineRenderer.
private LineRenderer lineRenderer;

void Start()
{
lineRenderer = GetComponent<LineRenderer>();
lineRenderer.positionCount = wayPoints.Length;
for (int i = 0; i < wayPoints.Length; i++)
{
lineRenderer.SetPosition(i, wayPoints[i]);
}
}


You might want to check the manual out as well.

• positionCount is the number of line segments, so positionCount is the total number of line segments, where each line segment has two waypoints as endpoints, right? So 'lengthOfLineRenderer' is 'wayPoints.Length - 1' right? – azemda Aug 31 '17 at 13:33
• Oh my mistake, I have edited that part. PositionCount is basically the number of points that lineRenderer uses to draw the lines. Say there are 10 points, there will be 9 vertexes in the line for instance. – Tolga Şen Aug 31 '17 at 13:54
• So, positionCount is waypoints.Length, and not waypoints.Length - 1, right? – azemda Aug 31 '17 at 14:03
• Yes, that's right. And the important thing is, wayPoints must include the position that player stands at the beginning. – Tolga Şen Aug 31 '17 at 14:17