How to display the trajectory of a nav mesh agent in runtime ?

Hi, I’m making a tactical rpg based on Divinity Orginal Sin 2 and to move the character I use Unity’s pathfinding, but I’d like the player to see which path the character will take before moving. I attach an image of what it looks like in Civ 5 (It’s not a tactical rpg but it works the same way). I have already tried to do it with the “render line” component but it was not working well. Thank you in advance for your help.


alt text

I know you said you already tried the render line component, but that really seems to be the best way and I would try that a little more before giving up; I found a link that looks very straightforward for you to create a script with and attach to whatever you are trying to draw the path for:

https://gamedev.stackexchange.com/questions/67839/is-there-a-way-to-display-navmesh-agent-path-in-unity

I have edited the above code, add this code to a new script you would create for your object and you can even plug in each one through the inspector:

public class Example: MonoBehaviour
{
	public LineRenderer line; //to hold the line Renderer
	public Transform target; //to hold the transform of the target
	public NavMeshAgent agent; //to hold the agent of this gameObject

	public void GetPath()
	{
	    line.SetPosition(0, transform.position); //set the line's origin

	    agent.SetDestination(target.position); //create the path
	    yield WaitForEndOfFrame(); //wait for the path to generate

	    DrawPath(agent.path);

	    agent.Stop();//add this if you don't want to move the agent
	}

	public void DrawPath(NavMeshPath path)
	{
	    if(path.corners.Length < 2) //if the path has 1 or no corners, there is no need
        	return;

	    line.SetVertexCount(path.corners.Length); //set the array of positions to the amount of corners

	    for(int i = 1; i < path.corners.Length; i++){
        	line.SetPosition(i, path.corners*); //go through each corner and set that to the line renderer's position*
  • }*
    }
    I hate to say it but if that doesn’t make sense then there wouldn’t be a more straightforward way to do what you are trying to do and that is probably the easiest solution available to you and literally made to do what you are asking.