My goal is basically to raycast from one part to another. This is to check if there is something interrupting the view of two parts. I know that when raycasting, the first argument is the origin (so the part’s position) and the second argument is the direction it shoots in?
So how exactly would I get this to shoot a line directly from one part to another part? Is there some crazy math? Am I just stupid?
It’s normalized (using the Unit property) to give it a length of 1, so you can scale it to be any length.
So implementing it, you’d have something like:
local rayLength = 15 --//How long the ray should be
local rayOrigin = part1.Position
local rayDirection = (part2.Position - part1.Position).Unit * rayLength
local rayResult = workspace:Raycast(rayOrigin, rayDirection)
It returns the same direction but with a length of 1, so it’s scaled down basically, giving you a vector that you can multiply to the length that you need it to be.
If you use the raw direction vector, you’re not going to get the results you’re anticipating. Depending on how far those parts are away from each other, you could get dramatically different results each time.
So using unit insures the length is the same every single time, so only the direction is what’s different.