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

How do you find the magnitude between two frames inside an ScreenGui?

Asked by 7 years ago
Edited 7 years ago

Using ROBLOX's WIKI page for magnitude I manged to make it work for bricks, now trying to find the magnitude between frames is not working as well :

WIKI : (http://wiki.roblox.com/index.php?title=Magnitude)

WORKING CODE :

local center = game.Workspace.center
local short = game.Workspace.short
local long = game.Workspace.long
local magnitude = (center.Position - short.Position).magnitude
print(magnitude)

Now the working code is ONLY for the bricks, but I am trying to make this move over to a ScreenGUI + ImageButton.

Would I need to make my own Vector3 values in order to get the position, because using [(frame.Position - frame2.Position).magnitude] gives me an error

This leads me to that fact I need to get in individual values of the UDim2 properties, which I don't know how to do and that's why I came here.

ERROR : magnitude is not a valid member, did you forget to capitalize the first letter? 13:30:37.945 - Script 'Players.Player1.PlayerGui.ScreenGui.ImageButton.Script', Line 5

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

You can use the Pythagorean theorem here. Simply plug in the X and Y values for the two objects .

dist = sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2)

This formula only works if your parts are positioned using the Offset property.

local center = game.Workspace.center
local short = game.Workspace.short
local long = game.Workspace.long

-- dist = sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2)

local magnitude = math.sqrt(((center.Position.X.Offset - short.Position.X.Offset) ^ 2) + ((center.Position.Y.Offset - short.Position.Y.Offset) ^ 2))
print(magnitude)

0
Do you mind giving me a filled in example, I am not very good at math, my apologies. UnleashedGamers 257 — 7y
0
Wil do - gimme a minute or so patrline5599 150 — 7y
0
No problem, take your time. Thank you. UnleashedGamers 257 — 7y
0
Did this end up helping you? patrline5599 150 — 7y
View all comments (2 more)
0
Thanks! UnleashedGamers 257 — 7y
0
It sure did! UnleashedGamers 257 — 7y
Ad

Answer this question