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

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

Asked by 1 year ago
Edited 1 year 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!

1 answer

Log in to vote
2
Answered by
aviel101 165
1 year 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 — 1y
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 218 — 1y
Ad

Answer this question