What is Part.Magnitude? I tried looking on the Roblox api but it would only list stuff like Lineforce.Magnitude
Maybe do you mean this?
local magnitude = workspace.MyPart.Position.Magnitude
print(magnitude)
Read More here: Vector3 | Roblox Creator Documentation
I have never heard of that. To my knowledge, only vectors have magnitudes? Did you mean to reference a magnitude of a part’s property?
You can’t get the magnitude of an instance, only a vector. The magnitude is some fancy vector thing that I still don’t quite understand, but here is the formula for getting one:
local magnitude = math.sqrt(vector.X^2 + vector.Y^2 + vector.Z^2)
/ local magnitude = (vector.X^2 + vector.Y^2 + vector.Z^2)^0.5
(Both methods work the same, just the former uses the sqrt method, and the other one raises it to the power of a half, which is the same as getting the root)
Or you can do:
local magnitude = vector.Magnitude
I’m not good enough at vectors to know what it does or when to use it, but I am pretty sure (correct me if I’m wrong) that it’s something like the direction of a vector? Or is that the unit of one, I don’t know.
You’re close! In a mathematical sense, Vectors have two components, to them - direction and magnitude. You use .Magnitude to get the magnitude, and you use .Unit to get the direction.
I still have no clue the formula for getting the unit vector. I’ve kind of seen magnitudes as either the direction or the “combined sum” / “single number” version of a vector. I just now remembered when I used .Unit
On a raycasting gun to get the direction of the fire part, so I guess I forgot when I made my original reply.
The unit vector is what you get when you divide everything by the magnitude
Magnitude of a vector is the distance from the origin (0, 0, 0
) to that vector. To get the magnitude, you use Pythagorean’s on all the axis:
The orange line is the X
axis, the blue line is the Z
axis, and the cyan line is the Y
axis.
local function getMagnitude(Vector: Vector3) -- Basically doing 3D Pythagorean's
local XZPythagoreans = math.sqrt(Vector.X^2 + Vector.Z^2) -- Getting the length of the green line
local YHypotenusePythagoreans = math.sqrt(XZPythagoreans^2 + Vector.Y^2) -- Getting the length of the yellow line
return YHypotenusePythagoreans
end
print(getMagnitude(Vector3.new(5, 4, 3))) -- Getting the magnitude from the origin (blue dot) to the vector (red dot)
-- Prints 7.0710678118655