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

Can someone explain magnitude for me?

Asked by 8 years ago

I was told in the community chat that using magnitude could tell the server the parts around a specific part. And after reading a article about it in the ROBLOX Wiki, it hasn't cleared anything up for me. Can anyone explain it a little less complex to me, so I can atleast get a good understanding of the basics of magnitude and I can begin to work on my game a bit more?

3 answers

Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

In physics, a vector is a thing with a direction and a length, also called a magnitude.

Examples of these are

  • velocity: direction is direction, magnitude is speed.

  • displacement: to get from A to B you travel m units in direction d. m is the magnitude.


Vectors can be added -- a + b means first moving along a then along b.

Thus if we want to get from place A to place B by moving x, we have the equation A + x = B. Algebra tells us that this means x = (B - A). This is a vector describing how to get from A to B. We can request the length of this vector by asking for x.magnitude.

Then to test if a point is close to another point, you just check if the distance between them is less than some certain amount.

Ad
Log in to vote
1
Answered by 8 years ago

In vector theory, magnitude is the length of the vector. It is gotten by the Pythagorean Theorem like so:

magnitude = sqrt(X ^ 2 + Y ^ 2 + Z ^ 2)

That will return the length of the vector.

In roblox, this is how we use it:

local Part1 = workspace.Part1
local Part2 = workspace.Part2

print((Part1.Position - Part2.Position).Magnitude)

This will print the distance(in studs) between the two parts.

You could have also done it with the Pythagorean Theorem like this:

local Part1 = workspace.Part1
local Part2 = workspace.Part2

local Delta = Part1.Position - Part2.Position

print(math.sqrt(Delta.X ^ 2 + Delta.Y ^ 2 + Delta.Z ^ 2))

Delta means the difference between two numbers basically. And if you look at "math.sqrt(Delta.X ^ 2 + Delta.Y ^ 2 + Delta.Z ^ 2)" You will see that that is the Pythagorean Theorem which is how magnitude is calculated. I hope this helps :)

Log in to vote
0
Answered by 8 years ago

Maginitude is the space between 2 objects. By default the magnitude would be the space between An object and the origin of the world unless defined otherwise. To change this you would do something like this local magnitude = (part1.Position - part2.Position).magnitude

Answer this question