I'm learning to use raycast and I am confused on one of the parts of the script, what does the part on the line below that says "unit*300" mean?
Help understanding that would be great
local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit*300) local hit, position = game.Workspace:FindPartOnRay(ray, user)
mouse.Hit.p
andtool.Handle.CFrame.p
are Vector3
objects. A Vector is a mathematical data structure representing some direction/position in 3D space, given in terms of x, y, and z coordinates. This Vector has both a direction and a magnitude (length/size), the unit
property returns a Vector3
that has the same direction as the the original Vector (tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p
in this case) - but with a length of 1.
Multiplying 1 by 300 gives 300, of course, so what you get out of it is a Vector3
pointing in the direction of where the mouse is pointing that has a length of 300 studs.