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

Yeah… But that would kinda break the game’s purpose…

I’m currently checking this thing out called GuiCollisionService

im pretty sure i found a solution:

repeat wait() until game:IsLoaded() wait(.5)

local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui

local frameA:Frame = playerGui.A.Frame -- assuming A is the screen gui name
local frameB:Frame = playerGui.B.Frame -- assuming B is the screen gui name

local function frame()	
	local positionA = frameA.AbsolutePosition
	local positionB = frameB.AbsolutePosition
	
	local sizeA = frameA.AbsoluteSize.X 
	local sizeB = frameB.AbsoluteSize.X 
	
	local size = math.max(sizeA,sizeB)
	
	local distance = (positionA - positionB).Magnitude
	
	if distance < size then
		print("Overlapping")
	end
end

game:GetService("RunService").Heartbeat:Connect(frame)

Oh i forgot to say, this will only work if anchor point is .5, .5 on both frames

1 Like

Thank you! I will for sure try this!

1 Like

YOOOO!!! THANK YOU SO MUCH, IT WORKED!! I REALLY APPRECIATE IT BRO! :smiley: :smiley: :smiley:

1 Like

This detects a touch of even a pixel. @InfinityGamingRBLX if you want something like agar.io, you want to check if the bigger circle is completely overlapping the smaller one.

Yeah i want it to happen even though a pixel is getting overlapped. Thanks for asking though!

okay, so i was playing around with the script for a while and realized there was a problem
when the frames are sized differently and the bigger one is on the right of the smaller one. here is the new script:

repeat wait() until game:IsLoaded() wait(.5)

local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui

local frameA:Frame = playerGui.A.Frame -- assuming A is the screen gui name
local frameB:Frame = playerGui.B.Frame -- assuming B is the screen gui name

local function frame()	
	local sizeA = frameA.AbsoluteSize.X 
	local sizeB = frameB.AbsoluteSize.X 
	
	local size = math.max(sizeA,sizeB)
	local min = math.min(sizeA,sizeB)
	
	local positionA = frameA.AbsolutePosition 
	local positionB = frameB.AbsolutePosition 
	
	if sizeA > sizeB then
		positionA += Vector2.new(math.abs(sizeA - sizeB) / 2,math.abs(sizeA - sizeB) / 2)
	else
		positionB += Vector2.new(math.abs(sizeA - sizeB) / 2,math.abs(sizeA - sizeB) / 2)
	end
	
	local distance = (positionA - positionB).Magnitude
	
	if distance < size - (size - min) / 2 then
		print("Overlapping")
	end
end

game:GetService("RunService").Heartbeat:Connect(frame)

when i tried this, it worked. hopefully this script has no problems.

2 Likes

Oh okay! No problem! Thanks again! :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.