How does magnitude and range work?

Alright, so I’ve been working on a game [not saying for privacy reasons and I don’t want the game idea to be stolen lol.] Anyway I’ve been using range and magnitude for NPCs and it’s been working well. Though I tried to display the range and see what it looks like with parts. I figured the most logical thing to do was to make a cylinder with the dimensions of Vector3.new(0.05,10,10) Though that didn’t line up? I’m not sure how magnitude and range are calculated, can anyone help me see how this works?

size
range

1 Like

I think magnitude is the overall distance around the entire object, range is how far something can see

Magnitude is linear while range is circular

the cylinder appears to be treating the activation radius as the diameter, which is why the turret appears to be shooting from twice the distance shown by the cylinder

radius == diameter/2
diameter = radius*2

try something like this:
Cylinder.Size = Vector3.new(0.05,MaxDis*2,MaxDis*2)

other than that everything appears to be working as intrended

1 Like

Thank you, this does help me see how these things work more. I always felt like they were off cause of this.

If you, or anyone else is wondering how .magnitude works, I made a functioning example of .magnitude, for comparing the magnitude of two points - basically the distance between them. And let me know if anyone has feedback on this, like if I’m doing something wrong - keep in mind it’s not customized for roblox Vector3 values (but the x,y,z is the same as how Vector3 works), but works for vanilla lua.

I like experimenting with formulas such as this - it’s fun!

local function magnitude(a, b)
    local delta = {math.abs(a[1] - b[1]), math.abs(a[2] - b[2]), math.abs(a[3] - b[3])}
    local mag = math.sqrt(delta[1] ^ 2 + delta[2] ^ 2 + delta[3] ^ 2)

    print("One: " .. delta[1] .. " Two: " .. delta[2] .. " Three: " .. delta[3])
    print("Magnitude: " .. mag)

    return mag
end

So example usage would be:

local firstPosition = {6, 2, 1}
local secondPosition = {1, 2, 6}

magnitude(firstPosition, secondPosition)

And the output for the above:

One: 5 Two: 0 Three: 5
Magnitude: 7.0710678118655

So basically, magnitude in this use-case subtracts the first vector’s values by the second vector’s values (vice versa), and takes the absolute value of the results from them. Then it uses the pythagorean theorum to calculate the final magnitude.

In turn, you could take the direct distance between any two objects in a 3D space that have vectors with the x, y, and z axis’. And you can use this for 2D points as well, by simply changing the formula to not include the z axis (the third number).

But anyhow, I hope I helped somewhat in understanding (to some degree) what’s happening behind the scenes with .magnitude. Have a great week!

5 Likes