How to detect if a part is fully within another part, when both parts have CanQuery off?

So I’m making a game where you can build things, and you build inside of a garage. But I only want the player to be able to build in a specific area. I have tried using GetPartsInPart but it doesn’t work, because the parts I’m working with have CanQuery turned off (long story). How can I still find out if the parts are fully within eachother?

I think in this case some bound math is required, check for positions and account for part size aswell, rotation is another universe

How do I do this? I’m unfamiliar with vector math, so I don’t really know how to do something like this.

local params = overlapParams.new()
params.BruteForceAllSlow = true

local parts = workspace:GetPartsinPart(part:part, params)
-- try that I think..
-- or use seperate collision groups!

-- you'd set the collision groyp by doing
params.CollisionGroup = groupExample

--you could also try using the getBoundsinBounds method considering you're 
--making a building area
1 Like

This, however, does not account for when the part is fully within another part. :GetPartsInPart() will return whenever there is any intersection of volume.

1 Like

I have an idea on how to solve my problem: I have one bounds area, where the part should be, and multiple ‘anti bounds’ areas, where the part shouldn’t be. To detect if a part was FULLY in the bounds area, you could check that it both:

  • Is touching the bounds area and
  • Isn’t touching any anti-bounds areas.

I think this system should work, the only thing I’m confused on is how to find if any two parts are touching. Any ideas?

P.S, bear in mind that I can’t use anything that relies on CanQuery.

I’m trying to do collision detection using Touched and TouchEnded, but the system doesn’t work: It might be because the script this is in is local. Here it is:

local collectionService = game:GetService("CollectionService")
local antiBounds = collectionService:GetTagged("Bound")

for _, bound:Part in antiBounds do
	
	bound.Touched:Connect(function(otherPart)
		if otherPart.Name == "GhostPart" then
			print("ooo")
			bound:SetAttribute("IsGhostPartTouching", true)
		end
	end)
	
	bound.TouchEnded:Connect(function(otherPart)
		if otherPart.Name == "GhostPart" then
			print("ahhh")
			bound:SetAttribute("IsGhostPartTouching", false)
		end
	end)
end

As of now, the IsGhostPartTouching attribute on parts with the Bound tag is not being updated, and the console is empty.

EDIT: I’ve put the logic that detects whether the ghost part is touching or not in a remote function, and everything works now!

1 Like

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