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

How do i detect gui collisions?

Asked by 8 years ago

Below is my current code. I'm able to get a boolean value if textLabel1 and textLabel2 collide but how would i run this code so that it checks all possible combinations? e.g textlabel 1 and textlabel 3

Thanks for any help

local function getPos(object)
    local posX = object.Position.X.Offset
    local posY = object.Position.Y.Offset
    return UDim2.new(0, posX, 0, posY)
end

local function getSize(object)
    local sizeX = object.Size.X.Offset
    local sizeY = object.Size.Y.Offset
    return UDim2.new(0, sizeX, 0, sizeY)
end
--[[
local function checkForCollisions(object,object2)
    if math.abs(object.Size.X.Offset + object2.Size.X.Offset)/2 >= math.abs(object2.Position.X.Offset - object.Position.X.Offset) and 
        math.abs(object.Size.Y.Offset + object2.Size.Y.Offset)/2 >= math.abs(object2.Position.Y.Offset - object.Position.Y.Offset) then
        return true
    else
        return false
    end
end
--]]

while true do
    for i, v in pairs(script.Parent.Buttons:getChildren()) do
        v.Changed:connect(function(property)
            print(i..": "..tostring(getPos(v)).."  "..tostring(getSize(v)))
        end)
    end

    --[[
    if checkForCollisions then
        checkForCollisions[1].Style = "RobloxButton" 
        checkForCollisions[2].Style = "RobloxButton" 
    else
        checkForCollisions[1].Style = "Custom"
        checkForCollisions[2].Style = "Custom"
    end

    checkForCollisions(script.Parent.Buttons.TextButton, script.Parent.Buttons.TextButton2)
    --]]

    wait(1)
end

1 answer

Log in to vote
0
Answered by
LostPast 253 Moderation Voter
8 years ago
0
Thanks dude, just wish you posted this an hour ago ;p jordan0810 55 — 8y
Ad

Answer this question