Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is unit 300?

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)

1 comment

0

Thank you duck

1 answer

✓ Accepted answer

mouse.Hit.p and tool.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.

This discussion is preserved as it was. New answers, comments, and votes are closed.