# Lerping Vectorisity spline

I am drawing a graph using Vectorisity. Every time I get a new measurement I would like to interpolate between the two states of the graph, the old data and the new. I am doing this using a coroutine, however it isn't working yet.

```
IEnumerator DrawGraph(Vector3[] coordinates, float duration)
{
float startTime = Time.time;
float endTime = startTime + duration;
while (Time.time <= endTime)
{
float t = (Time.time - startTime) / duration;
for(int i = 0; i < coordinates.Length; i++)
{
coordinates[i] = Vector3.Lerp(previousCoordinateArray[i], coordinates[i], t);
}
GraphSpline.MakeSpline(coordinates, coordinates.Length, false);
GraphSpline.Draw3D();
yield return null;
}
}
```

Could you suggest me any fixes?

It is not interpolating between the coordinates, it just snaps from one state to another.

Try replacing your yield return with:

```
yield return new WaitForEndOfFrame ();
```

It is still not working unfortunately. Here is a little bit larger snippet of my current code:

```
void DrawSpline(List<Vector3> coordinates)
{
Vector3[] coordinateArray = coordinates.ToArray();
if(previousCoordinateArray == null)
{
GraphSpline = new VectorLine("GraphSpline", new List<Vector3>(coordinates.Count + 1), GraphTexture, GraphLineWidth, LineType.Continuous);
GraphSpline.joins = Joins.Weld;
GraphSpline.continuousTexture = true;
GraphSpline.MakeSpline(coordinateArray, coordinateArray.Length, false);
GraphSpline.Draw3D();
}
else
{
//CreateStaticGraph(coordinateArray);
StartCoroutine(CreateGraph(coordinateArray, 5f));
}
previousCoordinateArray = coordinateArray;
}
IEnumerator CreateGraph(Vector3[] coordinates, float duration)
{
float startTime = Time.time;
float endTime = startTime + duration;
while (Time.time <= endTime)
{
float t = (Time.time - startTime) / duration;
for(int i = 0; i < coordinates.Length; i++)
{
coordinates[i] = Vector3.Lerp(previousCoordinateArray[i], coordinates[i], t);
}
GraphSpline.MakeSpline(coordinates, coordinates.Length, false);
GraphSpline.Draw3D();
yield return new WaitForEndOfFrame();
}
}
```

Looks like you might've been assigning the coordinates in reverse order.

What does it do if you try this:

```
IEnumerator CreateGraph(Vector3[] coordinates, float duration)
{
float startTime = Time.time;
float currentTime = Time.time;
float endTime = currentTime + duration;
while (currentTime <= endTime)
{
float t = (currentTime - startTime) / duration;
for(int i = 0; i < coordinates.Length; i++)
{
previousCoordinateArray[i] = Vector3.Lerp(previousCoordinateArray[i], coordinates[i], t);
}
GraphSpline.MakeSpline(previousCoordinateArray, previousCoordinateArray.Length, false);
GraphSpline.Draw3D();
yield return new WaitForEndOfFrame();
// Resample the time after that yield finishes
currentTime = Time.time;
}
// Snap these in case we have a timing issue
GraphSpline.MakeSpline(coordinates, coordinates.Length, false);
GraphSpline.Draw3D();
}
```

I have made it work, I needed to store the vectors from the lerping in a temporary array.

```
IEnumerator CreateGraph(Vector3[] coordinates, float duration)
{
float startTime = Time.time;
float endTime = startTime + duration;
while (Time.time <= endTime)
{
float t = (Time.time - startTime) / duration;
for(int i = 0; i < coordinates.Length; i++)
{
tempCoordinateArray[i] = Vector3.Lerp(previousCoordinateArray[i], coordinates[i], t);
}
GraphSpline.MakeSpline(tempCoordinateArray, coordinates.Length, false);
GraphSpline.Draw3D();
tempCoordinateArray = previousCoordinateArray;
yield return new WaitForEndOfFrame();
}
}
```

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.