Today I tried to learn RayCasting but what I don't understand is that when I Cast a Ray with its two Parameters(Origin Position, RayDirection), the Ray doesn't reach far enough when clicked because I use LocalPlayer:GetMouse().Hit.Position
. The methods Advance scripters use are
Tool.Position + (MousePosition - Tool.Position).Unit * Range
To scripters, the above makes the Ray go further than LocalPlayer:GetMouse().Hit.Position
This makes more confusion for me and bring's me to a question; What are Unit's and Magnitude's? ANY help regarding my question is appreciated!
Magnitudes
(pos1 - pos2).Magnitude will give you the distance between the two positions in studs
generally Magnitude will give you the length of the vector, so doing pos1.Magnitude will give you the length of the vector that starts from (0, 0, 0) and ends at (pos1.X, pos1.Y, pos1.Z)
Unit
Unit will give you the "Normalized Vector" of the given vector, meaning it will have the same direction, but it's Magnitude will be 1.
so in your example (MousePosition - Tool.Position).Unit
you take the Vector3 which it's magnitude 1 and it's direction from the tool position to the mouse position, and you multiply it by range to increase it's Length, meaning if you multiply the Normalized vector by 500 for example, it's Magnitude will be 500
if you have any questions feel free to ask.