Calculate a point - Closed Solved

Hi guys.
I have this problem where I have to calculate a vector3 point somewhere along a line.

Take a look at the attached image, in order to help me explain the problem.
A and B are vector 3 variables that I have, dist is the distance between A and C (the distance along the X axis).

And now I must calculate the vector 3 coordinates for C (actually, its just the Y coordinate).

Any ideias?

Use Vector3.Lerp.

–Eric

You use similar triangles for this.

Here’s how I think of it: calculate the fraction “t” which is how far you are from A to B. Since you have the distance along the X-axis, this is just t = dist / (B.x - A.x).

Then you can find Y simply as C.y = A.y + t * (B.y - A.y).

Or you can let Unity find the whole point at once as Vector3.Lerp(A, B, t). Under the hood, Lerp is simply doing math like the line above.

1 Like

Oh god it worked like a charm thanks alot! I’ve been at it the entire day!

I knew it had something to do with Lerp but I just could’nt find what was missing.

I was missing the ‘t’ calculation.

Thanks alot.

I’m glad I was able to help.