Hello, I am currently working on a game and I want to check if the distance between 2 GUIS is > a number. How do I do that?
Here is what I did but It’s not working:
if (clonedArrow.AbsolutePosition - script.Parent.Main.Right.AbsolutePosition).magnitude < 5 then
end
AbsolutePosition is a read-only property that provides the screen position of a UI element in pixels. This represents the actual pixel position at which an element renders as a result of its ancestors’ sizes and positions. The GuiObject.AnchorPoint also influences the AbsolutePosition.
Based on the name of the guis, I assume they are making an fnf game (popular rhythm game at the moment.) They would need to check if the arrows that are moving are inside the arrows at the top of their screen.
You would have to use math using the pythagorean theorem. This function returns the distance between two guis. This takes the top right corner, but if you needed the closest two corners you would need more math.
local function findDistance(Gui1, Gui2)
local X = math.abs(Gui1.AbsolutePosition.X - Gui2.AbsolutePosition.X)
local Y = math.abs(Gui1.AbsolutePosition.Y - Gui2.AbsolutePosition.Y)
local distance = math.sqrt(X^2 + Y^2)
return distance
end