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

What is mavnitude, where and how to use it?

Asked by
seikkatsu 110
5 years ago

Pretty self explanatory, i would like to get some more help on magnitude

0
And also i would like to know what kind of script i should it seikkatsu 110 — 5y
0
You're in luck. I wrote the above tutorial for this type of question. ;) User#29813 0 — 5y
0
nice tutorial royaltoe 5144 — 5y
0
that tutorial that phleg made is the one that inspired me to learn more about math :) starmaq 1290 — 5y

2 answers

Log in to vote
2
Answered by
starmaq 1290 Moderation Voter
5 years ago
Edited 5 years ago

Magnitude is always described as the "distance between two objects", which is totally wrong. .magnitude is a property of Vector3 (vector3, cframe and a lot of other datatypes count as an object) and magnitude simply means "length", and in other cases it might mean a quantity a size and everything that goes along that. Vectors (or we can day Vector3s as we know them in roblox) are lines that have a direction and a length, or as we said a magnitude.

Here is an example




local vector = Vector3.new(5, 2, 3) print(vector.magnitude) --prints out around 6.16, which is the length of this vector in studs

The most common use for .magnitude is finding the distance between two things. That's by subtracting the first position from the 2nd position (positions are just vector3s of course), that subtraction should gives us another vector that describes the distance between those two positions, so technically the magnitude of that vector is the distance between those 2 vectors. Think about it's pretty simple.

local distance = (part1.Position - part2.Position).magnitude

print(distance)

And this is not the only use for magnitude, there are A LOT especially when you're dealing with math. And really, here is a great advise, there isn't always an answer to "when would I use this?", what you should do is learn this stuff, and one day when you stumble across something you don't know, you try to think of a solution for that and maybe you needed the length of a vector so you use it!

Have a good day!

0
thanks for the indepth answer it helped seikkatsu 110 — 5y
0
np! starmaq 1290 — 5y
Ad
Log in to vote
2
Answered by
royee354 129
5 years ago

https://developer.roblox.com/en-us/articles/Magnitude

I mostly use it to find the absolute distance in studs between two objects, for an example:

Magni = (ObjectX.Position - ObjectY.Position).Magnitude

print(Magni)

it will print the distance in studs between the 2 objects

0
thanks nice tutorial seikkatsu 110 — 5y
0
no problem happy I could help :) royee354 129 — 5y

Answer this question