Help with RayCast vector math

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By russiniet

I suck at Vector math, so please help me. How do I find a global position of any point along the RayCast if I provide the distance from the origin? So, let’s say, the ray is coming from the position of the camera to another position. I want to find out the Vector3 of a global position at 10 units away from the origin along the ray. How do I do it? If it’s still confusing, here’s a diagram.enter image description here

:bust_in_silhouette: Reply From: njamster

If you normalize the cast_to-vector of your RayCast it maintains the same direction, but is shortened (or lengthened) to unit-length. So a point 10 units away from the origin of the ray is simply 10 * $RayCast.cast_to.normalized().

thank you very much, this works! So simple of a solution, i don’t know how I didn’t figure this out!

russiniet | 2020-04-15 23:07