For example, if I know (0.5, 4.9) and (6, 7.1), how can I find a vector on a line that crosses those 2 vectors?
Can you draw a picture? I’m not sure exactly what you are trying to accomplish.
say you have 2 points, p1 and p2, you can write a vector formula for a line that passes through those 2 points as:
p = p1 + (p2 - p1) * t
how I’d do it in code, and I’m going to normalize it so that t has a more predictable effect:
Vector2 p1 = new Vector2(0.5, 4.9);
Vector2 p2 = new Vector2(6, 7.1);
Vector2 v = (p2 - p1).normalized;
Vector2 somePoint = p1 + v * 3f; //gets a point on the line 3 units from p1
1 Like
Thanks @lordofduct this is exactly what I was looking for.
Note, it really is just the lerp formula.
You can use Vector2.Lerp as well… though the t won’t be representative of distance, but instead percentage from p1 to p2.