local function BoundaryCheck(Gui1, Gui2)
local pos1, size1 = Gui1.AbsolutePosition, Gui1.AbsoluteSize;
local pos2, size2 = Gui2.AbsolutePosition, Gui2.AbsoluteSize;
local top = pos2.Y-pos1.Y
local bottom = pos2.Y+size2.Y-(pos1.Y+size1.Y)
local left = pos2.X-pos1.X
local right = pos2.X+size2.X-(pos1.X+size1.X)
local In = true
if top > 0 then
In = false
elseif bottom < 0 then
In = false
end
if left > 0 then
In = false
elseif right < 0 then
In = false
end
return In
You might be able to fix that by adding to the size of one of the collision boxes by 1 in the equation. This would effectively make it detect other elements that are touching it’s exact border.
Also, now it’s X position has no effect on if it’s touching or not, it could be on the other side of the screen! All that matter is the Y position.
Code:
local function BoundaryCheck(Gui1, Gui2)
local pos1, size1 = Gui1.AbsolutePosition, Gui1.AbsoluteSize;
local pos2, size2 = Gui2.AbsolutePosition, Gui2.AbsoluteSize;
local top = pos2.Y-pos1.Y-(Gui1.Size.Y.Offset)
local bottom = pos2.Y+size2.Y-(pos1.Y+size1.Y)+(Gui1.Size.Y.Offset)
local left = pos2.X-pos1.X
local right = pos2.X+size2.X
local In = true
if top > 0 then
In = false
elseif bottom < 0 then
In = false
end
if left > 0 then
In = false
elseif right < 0 then
In = false
end
return In
end
I changed some parts in the code and managed to get down the amount of lines of code and fixed it so it worked for me. (Don’t know if I just used the code the wrong way)
local pos1, size1 = Gui1.AbsolutePosition, Gui1.AbsoluteSize;
local pos2, size2 = Gui2.AbsolutePosition, Gui2.AbsoluteSize;
local top = (pos1.Y) - (pos2.Y)
local bottom = (pos2.Y) - (pos1.Y)
local left = (pos1.X) - (pos2.X)
local right =(pos2.X) - (pos1.X)
local touching = false
if top < (size1.Y) and bottom < (size1.Y) and left < (size1.X) and right < (size1.X) then
touching = true
end
return touching
local function collidewith(gui1,gui2)
local gui1_topLeft,gui1_bottomRight = gui1.AbsolutePosition, gui1.AbsolutePosition + gui1.AbsoluteSize
local gui2_topLeft,gui2_bottomRight = gui2.AbsolutePosition, gui2.AbsolutePosition + 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