2

# [Solved]: What are Magnitude's and Unit's?

Asked by 13 days ago
Edited 12 days ago

## Hello My dear scripting fellows,

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!

2
aviel101 120
12 days ago

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.

0
Excellent answer. AZDev 590 — 12d
0
Well Done, You helped me out and strengthened me in the field of Unit's and Magnitudes. It will help me in future Projects. Thank You! Hi_People1133 168 — 12d