How to calculate raycast direction

to make a ray you need an origin and a direction. how do i calculate the direction? for example, if i want a ray to start at 0,50,0 and go to 27,45,82, how would i calculate the direction of that ray?

Its very simple you know this-

rayOrigin + rayDirection = rayDestination

So, by some simple math, subtract rayDirection on both sides
ray Origin + rayDirection - rayOrigin = rayDestination - rayOrigin

rayDirection = rayDestination - rayOrigin

So in your example, rayDirection will be (27, 45, 82) - (0, 50, 0) = (27, -5, 82)

6 Likes

(rayDestination - rayOrigin).Unit

thanks, didnt know its this simple