You just want to “normalize” the time for the whole path. Since you know the distances of the individual path segments you can calculate a weigthed fraction depending on the whole path.

In relation to the whole path (0 - 1) each segment only has a length of “segment length” / total length. Of course if you add up all those numbers in order you will get “1”. You can either store the absolute normalized starting time of each segment as well as the normalized length, or just store the normalized length and calculate the accumulated length as you’re searching for the current segment.

Imagine something like this:

```
public class Segment
{
public float nLength;
public Vector3 pos;
}
```

Here nLength is the normalized length as described above (so the segment length divided by the totel length). “pos” is just the target position. Usually when lerping along a path you could optimise the process be remembering the current used segment and the accumulated start time. If you want “random access” to the whole lerp range you would need to determine the right segment each time.

```
public static Vector3 PathLerp(List<Segment> aSegments, float aTime)
{
if (aSegments == null || aSegments.Count == 0)
throw new System.ArgumentException("segments not set","aSegments");
if (aSegments.Count == 1 || aTime <= 0f)
return aSegments[0].pos;
float acc = 0f;
float start = 0f;
int index = 0;
while(aTime > acc)
{
start = acc;
index++;
if (index >= aSegments.Count)
return aSegments[aSegments.Count - 1].pos;
acc += aSegments[index].nLength;
}
var seg1 = aSegments[index - 1];
var seg2 = aSegments[index];
return Vector3.Lerp(seg1.pos, seg2.pos, (aTime - start) / seg2.nLength);
}
```

Not that this is not tested. However the idea of the while loop is to determine the current target segment. Note that the first segment would just be the start position of your path and shouldn’t have any “length”. Since a path with n points only has “n-1” segments between those points. “aTime” is just the normalized lerp time for the whole path. “start” is the calculated starting time of the current segment. So we just subtract the starting time from the current time and divide by the normalized length of the current segment to get a value between 0 and 1. As long as you increase “aTime” at a constant speed you should move along the path with a constant speed.

As i said in most cases you just want to linearly move along the path. In this case you can get rid of the while loop as long as you remember the last index.

```
List<Segment> segments;
int current = 1;
float t = 0f;
void Update()
{
if (current > 0 && current < segments.Count)
{
t += speed * Time.deltaTime / totalLength / segments[current].nLength;
if (t>1f)
{
t -= 1f;
t *= segments[current].nLength;
current++;
if (current >= segments.Count)
return;
t /= segments[current].nLength;
}
pos = Vector3.Lerp(segments[current-1].pos, segments[current].pos, t);
}
}
```

This, again, is untested but should work. To actually initialize the segments you have to calculate the normalized length.

```
float totalLength = 0f;
for(int i = 1; i < segments.Count; i++)
{
segments_.nLength = Vector3.Distance(segments[i-1].pos, segments*.pos);*_
```

*totalLength += segments*.nLength ;**

*}*

*for(int i = 1; i < segments.Count; i++)*

*{*

*segments*.nLength /= totalLength;**

*}*