#Gui Touching Gui

1 messages · Page 1 of 1 (latest)

torn barn
#

I need to know how gui is touching other gui for my 2d game

crisp glade
#

i think you have to script ts yourself theres no touch detection for guis

tropic saddle
#

@torn barn, here is a simple code to know if a UI is touching another UI. There is no Roblox function that detects thats.

local function isTouching(gui1, gui2)
    local g1Pos, g1Size = gui1.AbsolutePosition, gui1.AbsoluteSize
    local g2Pos, g2Size = gui2.AbsolutePosition, gui2.AbsoluteSize

    return g1Pos.X < g2Pos.X + g2Size.X
        and g1Pos.X + g1Size.X > g2Pos.X
        and g1Pos.Y < g2Pos.Y + g2Size.Y
        and g1Pos.Y + g1Size.Y > g2Pos.Y
end
#

.

And here another type of code for like more than 2 type of UI

local function isTouching(g1, g2)
    local p1, s1 = g1.AbsolutePosition, g1.AbsoluteSize
    local p2, s2 = g2.AbsolutePosition, g2.AbsoluteSize

    return p1.X < p2.X + s2.X
        and p1.X + s1.X > p2.X
        and p1.Y < p2.Y + s2.Y
        and p1.Y + s1.Y > p2.Y
end

local function checkAll(guiList)
    for i = 1, #guiList do
        for j = i+1, #guiList do
            if isTouching(guiList[i], guiList[j]) then
                print(guiList[i].Name, "is touching", guiList[j].Name)
            end
        end
    end
end

example

local guis = {Frame1, Frame2, Frame3, Frame4}
checkAll(guis)
torn barn
#

your a life saver

#

do i run these repeatedly if i want it to check constantly?

#

works perfectly your such a G

formal geyserBOT
#

studio** You are now Level 1! **studio

tropic saddle
torn barn
#

its good now figured it out