Need help with 2D GUI collision and GUI "eating" system

I’ll try to keep it simple:

My plan is to make a system for when 2 objects with certain names touch eachother,
the smaller one gets “eaten” or destroyed by the big one. So basically it has to detect collision, then check the names, then check the size and then destroy the smaller one.

image

I really hope anyone can help! :smiley:

1 Like

You can do like: if A overlaps B then the size of B gets added with A’s current size and then destroy A

Yeah, but i don’t really know how to start with that. And i don’t know but wouldn’t that be really unoptimized?

1 Like

If I can remember, there’s PlayerGui:GetUIObjectsAtPosition() that you can use to know if one is overlapping another

1 Like

I will try that, i really hope it just won’t affect my game’s performance. Thanks in advance!

1 Like

Just remember to check if what I said is correct! I’m on my phone and can’t verify it on studio but I’m certain that a function like that exists because I use it

Okay, i will check. And oh yeah, keep in mind that my objects are circular due to UICorners.

1 Like

but which position will you put in? if you put in the position of the object, wouldn’t that just be the center?

1 Like

You can also do 4 checks simultaneously. Each one checking each side of the circle. This is the only way I know how to know if two frames are intersecting each other

Oh yeah! I could try to check on 4 sides

1 Like

what if it’s overlapping the corner?

1 Like

I will just make the sides on the insides?

1 Like

Add 4 more on the 4 corners. It’s that simple

1 Like

Though idk if that is the best thing to do. I am not an expert on luau

yeah, i guess that would work. just it might be laggy if youre checking a bunch of positions every moment.

1 Like

Yeah… But both of these have problems right?

2 Likes

Or i will try to figure something out with circle math??? I’ll see what i can do.

idk what you can do about the squares

What if i’d do:

local circle = --Path to circular object

local area = math.pow( circle.AbsoluteSize.X , 2) / 2 * math.pi

game:GetService("RunService").RenderStepped:Connect(function()
      --Do something with the area???
end)

I dont know it’s worth making the “hitboxes” accurate to a circle because that would slow down the game considerably more than just having the hitboxes as squares.