Calculating Direction for a ray

Can anyone help me understand how to calculate direction for a ray?

workspace:RayCast takes the direction as the 2nd parameter, you can just use the 2nd parameter. If you mean getting the direction by getting the degree, use this formula:

local Y = 3 -- Opposite
local X = 3 -- Adjacent

print(math.deg(math.atan(Y/X))) 
-- Or
print(math.deg(math.atan2(Y,X)))

If you have a ray, you already have a direction. Ray construction takes two arguments, the origin (a vector representing a position where the ray starts), and a second vector which represents both the magnitude and direction of that ray. Is there a specific direction you’re looking to solve for? Or are you confused on how the direction vector is interpreted? Perhaps it might be beneficial if you elaborated on what you’re looking to accomplish.

If you are asking how to calculate the direction parameter between two positions for raycasting then here you go:

local Position1 = ...
local Position2 = ...

local UnitVector = (Position1 - Position2).Unit
local length = (Position2 - Position1).Magnitude

local direction = unitVector * length