Search Unity

Drawing an advance Debug line

Discussion in 'Scripting' started by BubyMB, Jun 11, 2016.

  1. BubyMB

    BubyMB

    Joined:
    Jun 6, 2016
    Posts:
    140
    Hey guys! just wondering how would one draw a debug line to fit with pathfinding.
    I am using this code right now;
    Code (csharp):
    1.  Debug.DrawLine(transform.position, nav.destination, Color.red);
    Which only draws a line directly from the player to the destination, how would I make the line form in a shape which follows the way the player will go
     
  2. jimroberts

    jimroberts

    Joined:
    Sep 4, 2014
    Posts:
    560
    You would need to plot positions along the curve of the players movement and then iterate over the positions using Debug.DrawLine(previousPosition, nextPosition, color);
     
  3. BubyMB

    BubyMB

    Joined:
    Jun 6, 2016
    Posts:
    140
    oh found a good solution thanks!
    code if anyone wants it;
    Code (csharp):
    1.  for (int i = 0; i < nav.path.corners.Length - 1; i++)
    2.         {
    3.             Debug.DrawLine(nav.path.corners[i], nav.path.corners[i + 1], Color.red);
    4.         }