How to check if two parts will overlap if moved

So the concept here I am trying to work on is a part storage bin. The bin is covered on top/bottom/left/right/back and open in the front. I have a script that moves a part to the bin like so: Where part is an instance of a part, and storage is an array of models. (This was just test code to get started).

function MovePartToStorage(part, storage)
	part.CFrame = storage[1]:GetPivot()
        part.Parent = storage[1]
end

What I’m trying to do is now add to this function a condition where I check if the bin is full (the easy solution) I was thinking of doing something like check if the part’s CFrame would overlap with any of the parts in storage[1] before I move the part. Does that make sense? So I would have something like “If part not overlap storage parts then move” kind of thing (psuedo code below). Otherwise if the part would overlap then don’t move.

function MovePartToStorage(part, storage)
wouldOverlap = false
for each existingpart in storage children do
    if existing part would overlap part then
        wouldOverlap = true
    end
    if not wouldOverlap then
        move part
    end
end

The goal here is to avoid putting a part into the bin if the bin is “full” a.k.a. there is no area within the storage bin that part could fit. I was originally going to try to write code to see if I could find “open space” in the bin but that’s probably a more complicated calculation for a future improvement. Right now I just want to see if moving the part to the model’s pivot, would it overlap any other part has has previously been moved.

When the part moves, it is not anchored so would fall down and theoretically this could happen several times before that pivot cframe would eventually cause a part to overlap. Think like adding circles to a square and the circles fall to the bottom, eventually you’ll add a circle that overlaps a previous circle.

I cannot seem to find a way to check if two CFrames overlap. Unless I’m missing something obvious, is this something I have to do a 2d spacial overlap computation for or is there an easier way to do this, maybe a prebuilt function?

I’m a bit confused on what you’re doing with your storage, but you can likely handle it all with just a table. But if not, you can use GetPartsInPart or something similar.

Basically I want to check if I were to move a part to a Model’s center point, would the part that would be moving, overlap with any part within that model. If so, don’t move the original part, otherwise move that part. Trying to automatically detect if a storage bin (Model) is “Full” based on overlapping parts. I’m unable to determine if GetPartsInPart would work before the part is moved to the model but I’ll look into it. Thank you!

You can use a proxy part, but you can also use GetPartBoundsInBox for the exact position. Just give it a reasonable size that isn’t 0,0,0.

Gotcha, thanks. Let me play around with this a bit and I’ll solve/close this with your answer.