Hello,
I have a pretty weird problem with the LineRenderer component:
I want to join each WayPoint (capsule) of my scene with LineRenderer in a progressive way. I managed to do it with the code below but each time it touches a WayPoint (capsule), a line is created to the point 0,0,0 for 1 frame before disappearing. I do not understand … my code is correct and does not mention doing that.
my assumption is that it comes when I increment its size ‘’ lineRenderer.positionCount ++ "which makes me create a time 0,0,0 before the position changes.
Do you have an idea to avoid this temporary line please? Here is my code that
I commented the 5/6 lines of code concerned by the LineRenderer with ‘’ // here ‘’:
LineRenderer lineRenderer;
private int indexLine = 0;
public float linearSpeed = 5;
private void Start()
{
lineRenderer = gameObject.GetComponent<LineRenderer>(); //here
lineRenderer.positionCount = 1; //here
lineRenderer.SetPosition(0, start.transform.position); //here
NavigateTo(start, end);
}
void Update()
{
if (currentPath != null && currentPath.Count > 0)
{
if (moveTimeCurrent < moveTimeTotal)
{
moveTimeCurrent += Time.deltaTime;
if (moveTimeCurrent > moveTimeTotal)
moveTimeCurrent = moveTimeTotal;
var pointALongLine = Vector3.Lerp (currentWaypointPosition, currentPath.Peek(), moveTimeCurrent / moveTimeTotal); //here
lineRenderer.SetPosition(indexLine, pointALongLine); //here
} else
{
currentWaypointPosition = currentPath.Pop();
if (currentPath.Count == 0)
Stop ();
else
{
lineRenderer.positionCount++; //here
indexLine = indexLine + 1; //here
moveTimeCurrent = 0;
moveTimeTotal = (currentWaypointPosition - currentPath.Peek()).magnitude / linearSpeed;
}