So i made this topic because i’m expermenting on a gui game just like on arcafe but i want it to do something when 2 of my desired ui elements touched how can i implement it.
I tried doing an if statements subtracting the position of the 2 ui and checking if it was small but it doesn’t work
function UIElementsIntersecting(a, b)
return (math.abs(a.AbsolutePosition.X - b.AbsolutePosition.X) * 2 < (a.AbsoluteSize.X + b.AbsoluteSize.X)) and
(math.abs(a.AbsolutePosition.Y - b.AbsolutePosition.Y) * 2 < (a.AbsoluteSize.Y + b.AbsoluteSize.Y));
end
This code will return true when the two given UI elements are intersecting, and false when they are not.
Use this to check if they are “Touching”. Keep in mind that this code only works when the boxes are not rotated. If you need it to work for rotated boxes too, then you’ll need a different snippet of code, which is heavier on the CPU.
It depends on how your GUI is setup. You can remove the == true since it’s implicit, and remember to do this on RenderStepped since this is a function that requires constant checking.