Is there a way to check that parts are overlapping by more than a value?

I want to only get parts that are overlapping another part by more than 0.5 of a stud. Is there a way to do this? OverlapParams.Tolerance was my first guess but it can’t be negative, which seems weird because i recall there being some way to do this with overlapparams but don’t remember what it was.

1 Like

This might work out:

local ws = game:GetService("Workspace")
local part = ws:WaitForChild("Part")

local params = OverlapParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = ws:GetDescendants()

local function overlap(aMin, aMax, bMin, bMax)
	return math.max(0, math.min(aMax, bMax) - math.max(aMin, bMin))
end

local parts = ws:GetPartsInPart(part, params)
for _, other in ipairs(parts) do
	if other ~= part then
		local aMin, aMax = part.Position - part.Size/2, part.Position + part.Size/2
		local bMin, bMax = other.Position - other.Size/2, other.Position + other.Size/2
		if overlap(aMin.X, aMax.X, bMin.X, bMax.X) > 0.5 or
			overlap(aMin.Y, aMax.Y, bMin.Y, bMax.Y) > 0.5 or
			overlap(aMin.Z, aMax.Z, bMin.Z, bMax.Z) > 0.5 then
			print(other.Name)
		end
	end
end

I feel like I’ve answered this question more than a few times now, maybe not this exact way. I did a few tests with this version of it. It seemed to work. May need some tweaking. Good luck.

Cheers! Hope this helps someone. I ended up downsizing my parts to avoid this issue. Hopefully something so trivial becomes more straightforward to do eventually.

1 Like

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