TLDR: Should i multiple (vector2 - vector1).Unit By 1000 or keep it as it.
Im pretty sure the ray will cast either way but I have done some research and its saying it will change how far the ray will cast.
Im Making a module script that is just easier Raycasts and what not and I have this function that will cast a ray between 2 points. I need to know if I should be multiplying the unit.
Code
function RayCast.TwoPointDir(p1 : Vector3, p2 : Vector3)
return (p2 - p1).Unit * 1000
end
Suppose you have a function that uses this direction to perform a raycast:
local start = Vector3.new(0, 0, 0)
local end = Vector3.new(10, 0, 0)
local direction = RayCast.TwoPointDir(start, end)
local ray = Ray.new(start, direction)
local hit, position = workspace:FindPartOnRay(ray)
-- Example without multiplying
-- The ray will cast exactly from (0, 0, 0) to (10, 0, 0)
If you use the direction without multiplying, the ray will only cast for the distance between p1 and p2. If you multiply by 1000, the ray will cast in the same direction but for a much longer distance, which could be useful for detecting objects far beyond p2.
Conclusion
Multiply by 1000 if you want the ray to extend much further than the distance between p1 and p2.
Do not multiply if you want the ray to cast exactly between the two points.