We use cookies on this site to enhance your user experience

Jul 02 2018, 5:41 PM PST 2 min

“Magnitude” is a term used across mathematics that can mean several things. In vector theory, the magnitude of a vector is the length of a vector.

The length of a vector v is calculated using Pythagoras as follows:

  |(x, y)| = sqrt(x<sup>2</sup> + y<sup>2</sup>)

Or in 3 dimensions:

  |(x, y, z)| = sqrt(x<sup>2</sup> + y<sup>2</sup> + z<sup>2</sup>)

Distance between points


Often, it is useful to find the distance between two points. Let’s use the blue line for example. We have a vector that starts at point (1, -5) and ends at point (3, -3). Firstly, we need to subtract one from the other to get the line vector. This gives us (2, 2).

Now, if we imagine a vertical line coming from (2,2) to the x-axis, a right triangle is formed, with a from the origin, and Pythagoras’ theorem can be used to find the length of the hypotenuse:


a2 + b2 = c2

Commonly, in Roblox and other situations in need of finding the distance between two points, it is also referred to as the “distance formula.” Roblox has a special property for “Vector3” and “Vector2” values that does the math for finding the magnitude of the value for you. Here is how it can be indexed:


As you can see, any Vector3 has the magnitude property (this also includes Vector2 values). Now the simplest way to find the distance between two points (parts in this case) in Roblox is to run the following code (edit to fit your needs):

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