Why exactly do people use '.Magnitude' for purposes that aren’t to get the distance between two Vector3’s?

More and more often I see developers and other people using Vector3.Magnitude to represent a Vector3 as a single number instead of using it to get the distance.
e.g.

Velocity = someVector3.Magnitude
—or
Speed = someOtherVector3.Magnitude

instead of

distance = (someV3Position1 - someV3Position2).Magnitude

Please forgive me if I missed something I just simply don’t understand why you would use something meant to grab the distance for other things.

Could someone please explain?

Vectors contain two components, direction (.Unit) and magnitude (.Magnitude).
Magnitude isn’t strictly for measuring distance, it’s to measure size. Distance is a “size” between two points.
Speed is a “size” of a velocity.

Hm, I think I kinda get it. Is there anything to compare this “size” to though?

Let’s say we have a car moving at a velocity of (20, 0, 0).
The magnitude, or “size” of this vector would be 20. This is a scalar value, meaning without direction.
The unit or direction of it would be (1, 0, 0). This is a value without scale.

Another way to look at it would be something like 5 miles north.
5 miles is the distance or magnitude, north is the direction.

So magnitude is used instead because its easier to write than math.abs(someVector3.X)?

I understand what you mean I just don’t see that big of a difference.

A vector’s magnitude is the square root of the sum of all of it’s components squared.
magnitude = sqrt(vector.X^2 + vector.Y^2 + vector.Z^2)
I’m not saying you can’t use math.abs(someVector3.X) if you only wish to utilize that single axis, but there’s a substantial difference if you want the scale of the entire vector.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.