- Home /
Find a position by knowing the directionVector and the distance to this point
Hey,
I am trying to find a targetpoint behind an object. I do a raycast with a specific length. If the raycast hits an collider the targetpoint is set at the hitpoint. But if the raycast doesnt hit anything, i know that the way to this point is clear.
Now i must find this position, cause the raycast doesnt hit anything i cant read any information about the endpoint. So how can i find a point, given the directional Vector and the edge length to my targetpoint?
Thanks in Advance
Answer by syclamoth · Jan 29, 2012 at 01:25 PM
If you have a vector and a length, you can find the endpoint by using-
endPoint = startPoint + (vector.normalized * length);
If you have a ray, you can use
ray.GetPoint(length);
Thank you syclamoth! I also found a solution by using "Vector3.forward * length" cause a directional vector is exactly 1 unit long.
TransformDir(V.forward);
is the real operation -- convert your local space coords into world, you at (0,0,0) for both. transform.forward
is a (written, not run-speed) short-cut. If you're used to thinking about coordinate spaces, trans.forward
is confusing, seems like it hides the math.
TransDir is also more flexible (`TransDir(new Vector3(3,6,0))` vs trans.right*3+trans.up*6
) and maybe a little less error-prone -- easy to confuse V3.right with trans.right. It's also a nice lead-in to InverseTransDir, which can be used to check if something is left/right of you in your local space.