Every time I try to use Vector3.Project; it NEVER WORKS the way I expect. I have tried numerous examples I have found on here, and they never ever work.
I have a line made of points A and B, and a point P that I would like to project on this line. I have tried this:
Vector3 V1 = A - P;
Vector3 V2 = Vector3.Project(V1, A.NormalTo(B));
//return P + V2; this did not work either
return A + V2;
// NormalTo is an extension method I added to get a normal to a point. here is the definition:
public static Vector3 NormalTo(this Vector3 from, Vector3 to) {
return (to - from).normalized;
}
The code was taken from the top post on here for Vector3.Project() (via google search).
This always places the point in some weird place not on the line, but in the proximity of it.
What in the hell am I doing wrong? This function mystifies me.