The most I could find about this question in solutions was for one part as bounds, not multiple. Here’s what I consider “within bounds” and not. Gray being bounds and green and red being the target part to check. The part doesn’t have to be in all other bound parts, one works. This would account for all sizes and CFrames for the part. I’m looking to write a function which returns a boolean. Bounds would be parts inside a folder. How would I do this?
The function you want already exists as part of the spatial query update a year or so ago. Use workspace:GetPartsInPart or workspace:GetPartBoundsInBox and limit the OverlapParams to a maximum of 1 part.
local bounds = workspace.Folder --a container with the parts
local target = workspace.Part
local olp = OverlapParams.new()
olp.FilterDescendantsInstances = {bounds}
olp.FilterType = Enum.RaycastFilterType.Include
olp.MaxParts = 1
print(workspace:GetPartsInPart(target, olp)[1] ~= nil)
Thank you for your reply, I just tried this out and if the target part is partially within bounds it returns true. I need it to be fully within bounds. What could be the cause of this?
A possible solution would be to have a “skin” boundary that wraps around the region. In addition to the first query, you check a second time to see if the part is also queried by the wrapper region. A fully within bounds part in this case would return true for the first query, but false for the second query.
Another possible solution is to query the edges of the part with an infinitely small hitbox. All corners would need to be within the bounds, but with this approach the problem is that the part may not necessarily be a brick.
Simplest way would be to use a Union and have the inner boundary subtract from it. But if you have reservations on using unions, then you have to do it by hand