Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I calculate the magnitude in UDim2?

I need a gui object to be in a limit distance from other, but how to use it like Vector3, that has .magnitude? Do I have to calculate each vector, like:

distanceX = gui1.X.Offset - gui2.X.Offset

3 comments

0

I'm pretty sure you can only use Magnitude with Vectors.

1

That's not true

0

You could calculate it like that but it depends if you're using the bottom or right sides/corners. You'll need to add the width/height to the offset in that case.

1 answer

✓ Accepted answer

You can calculate the magnitude of the distance between the GUIs by comparing their AbsolutePositions:

local gui1s = gui1.AbsolutePosition
local gui2s = gui2.AbsolutePosition

local distance = (gui1s - gui2s).magnitude

4 comments

0

yeah I've thought of that, thanks for the code

0

but I didn't think of using absolute pos

0

and since absoluteposition is vector2, there is a .magnitude

0

Just discovered that, the wiki didn't say it.

This discussion is preserved as it was. New answers, comments, and votes are closed.