Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I calculate the magnitude in UDim2?

Asked by
Tesouro 407 Moderation Voter
10 years ago

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
0
I'm pretty sure you can only use Magnitude with Vectors. xImmortalChaos 565 — 10y
1
That's not true Muoshuu 580 — 10y
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. FearMeIAmLag 1161 — 10y

1 answer

Log in to vote
4
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

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
0
yeah I've thought of that, thanks for the code Tesouro 407 — 10y
0
but I didn't think of using absolute pos Tesouro 407 — 10y
0
and since absoluteposition is vector2, there is a .magnitude Tesouro 407 — 10y
0
Just discovered that, the wiki didn't say it. adark 5487 — 10y
Ad

Answer this question