How would I get a line renderer in unity to update to show where my character is moving to?

How would I get a line renderer in unity to update to show where my character is moving to?
The white line is what I am trying to make go around the walls instead of through them, I found in the seeker script something about drawing gismos which I am guessing is the green line you see in the editor but I am a bit of a beginner so I do not really understand the method that does it tbh…

Hi

You can use the ai.GetRemainingPath function to get some points for your line renderer.
See IAstarAI - A* Pathfinding Project

How do I get access to this method?

GetComponent<IAstarAI>().GetRemainingPath(...)

Wow that was fast response

Hey again, I cannot figure out how to do it right with LineRenderer.SetPosition, I sometimes get an error of LineRenderer.SetPosition Index was out of bounds and it only makes the line go up to the nearest point I believe, I know this because sometimes I can see it but its like right next to the player, This is the code I have got currently:

oh my lord I just realised I am getting component every frame lol I forgot to move it


My new code

You need to set the positionCount since the buffer might contain more points than you have configured it for, but I would recommend just using SetPositions (not s at the end) instead.

I tried using setpositions but it didn’t work either

Still sets it to the nearest point not all of them
image

Ah. From the Unity docs:

Note that positionCount must be called before SetPositions. Also SetPositions ignores points with indices beyond positionCount.

So I would do this:?

>         for(int i = 0; i < buffer.Count; i++)
>         {
>             lr.positionCount = i;
>         }

YES I got it working :smiley: Thanks man!

1 Like