Hi, I’m working on a way to draw a path in the game for the user to see. Aron has suggested using Vectrocity or the built-in Line Renderer. The Line Renderer uses an array of points, so my first step is locating an object’s AIPath data. I’m currently using Point Graphs. How do I go about finding the currently calculated path (exactly as drawn with gizmos in the editor windows) and the positions for each node along that path? Do I need to access the GraphNode list called ‘path’ within the Path.CS script?
I will be at this for hours so I figured someone might be able to “point” me in a likely direction. Thanks for any help, and thanks Aron for making this!!
If anyone else is searching for the same solution, here’s what worked for me. I changed the AIPath, Path variable to public. With the following incantation applied to a script on my LineRenderer I get an in-game visual of the path, presto! Here are the magic words:
myLineRend.positionCount = playerAIPath.path.vectorPath.Count;
for (int i = 0; i < playerAIPath.path.vectorPath.Count; i++) {
myLineRend.SetPosition (i, playerAIPath.path.vectorPath [i]);
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pathfinding;
//Create Class that inherits from another class
public class AIPathCustom : Pathfinding.AIPath
{
public int GetPathLength()
{
return path.vectorPath.Count;
}
public Vector3 GetPathPosition(int theIndex)
{
return path.vectorPath[theIndex];
}
}
public class LinePath : MonoBehaviour {
public AIPathCustom playerAIPath;
public LineRenderer myLineRend;
void Start(){
InvokeRepeating ("ResetLine", 0, .5f);
}
public void ResetLine() {
//print ("linePath resetLine");
if (playerAIPath.hasPath) {
//print (playerAIPath.path.vectorPath.Count);
myLineRend.positionCount = playerAIPath.GetPathLength();
for (int i = 0; i < playerAIPath.GetPathLength(); i++) {
myLineRend.SetPosition (i, playerAIPath.GetPathPosition(i));
}
} else {
Debug.Log("no path", gameObject);
}
}
}