Store array of points between 2 objects

Hi

I’m probably being really stupid here but I can’t figure out how I do this.

I have two points in my game - origin and destination. I want to do a kind of Lerp to get an array of x amount of Vector3 positions between those 2 points.

Something like:

location1 = Vector3(0,0,0);
location2 = Vector3(10,0,0);
arrayOfPoints = Lerp(Vector3(location1,location2,1.0);

So the results would be something like an array of 10 Vector3 values:
(0,0,0)
(1,0,0)
(2,0,0)
(3,0,0)
etc…

I’m not sure if Lerp is what I should be using to do that. Is there any way?

Thanks,
Dan

Vector3 location1 = Vector3.zero;
Vector3 location2 = new Vector3(10,0,0);
Vector3[] arrayOfPoints = new Vector3[10];

int i = 0;
for(float y = 0.0f; y < 1.0f; y += 0.1f) {
 
          arrayOfPoints[i] = Vector3.Lerp(location1, location2, y);
          i++;

}

Ahh, nice one.

That’s perfect - thanks. :slight_smile: