Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is unit 300?

Asked by 10 years ago

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)

0
Thank you duck BrokenPhilosophy 5 — 10y

1 answer

Log in to vote
4
Answered by
duckwit 1404 Moderation Voter
10 years ago

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.

Ad

Answer this question