Checking if a Frame is inside another Frame

How would I create a function which can tell me if a gui object such as a TextLabel/Frame is inside another gui object. Not parented but actually inside it position & size wise, hope I explained that right.

This can be found through searching the devforum (especially using the keyword 2D collision) , there are a couple topics on it and there are a couple of ways of doing it

The main thing is when finding if a Gui is inside another Gui, you’ll want to be comparing AbsolutePosition and AbsoluteSize to determine the bounding area of the Guis (if that makes sense)

An example way to do it is something like this:
(Edit: Found the source of this particular example, it comes from scripting helpers)

function collidesWith(gui1, gui2) ---A little different wording but it serves the same purpose
    local gui1_topLeft = gui1.AbsolutePosition
	    local gui1_bottomRight = gui1_topLeft + gui1.AbsoluteSize
 
	    local gui2_topLeft = gui2.AbsolutePosition
    local gui2_bottomRight = gui2_topLeft + gui2.AbsoluteSize
	 
	    return ((gui1_topLeft.x < gui2_bottomRight.x and gui1_bottomRight.x > gui2_topLeft.x) and (gui1_topLeft.y < gui2_bottomRight.y and gui1_bottomRight.y > gui2_topLeft.y))
end
10 Likes

Thanks for the help. :slightly_smiling_face: