Detect touch between anchored parts

So I have tried to use the Touched event and GetTouchingParts but none of them worked. Any other way I can detect them?

image

local Parts = --folder

for i,v in ipairs(Parts:GetDescendants()) do
	if v:IsA("BasePart") then
		local touchingParts = v:GetTouchingParts()
		
		for _, part in pairs(touchingParts) do
			print(part)
		end
	end
end

If two anchored parts are right next to each other, they won’t detect a touch. But if one of the parts are slightly inside the other, you can detect them using GetTouchingParts. I don’t know what you plan to use this for, but if you are using it for a building system of sorts, you could create a secondary, invisible part that will act as the touch detector of sorts.

Here’s a diagram to explain it easier:

The blue forcefield part would be the touch detector, though you will have to filter out the red part since the blue part touches the red one as well.

1 Like

Yes, but I have a lot of parts in the model.

Spatial Query - GetPartsInPart

But that would only for workspace?

Could you give us more details and context about what you are trying to use this for or where its parented, etc.? That would help us a lot.

I’m trying to make a destructible wall that will break into pieces.

Unfortunately, yes. If you wanted to do it otherwise then I believe the only way to do it is to make your own geometry collision detection. I believe EgoMoose has made a module that can do this, or you can make your own

I do recommend against it as there are very few scenarios in which you wouldn’t have geometry in the workspace

Does it work with this?

image

That is in the workspace, so yes.

I also have meshparts that needs to be welded on touch. Anything that would help with that?

I would suggest the constraint version of welds, WeldConstraints

I don’t know how to use this module.

current script:

for i,v in ipairs(Parts:GetDescendants()) do
	if v:IsA("BasePart") then
		RotatedRegion3.FromPart(v)
		local parts = RotatedRegion3:FindPartsInRegion3WithWhiteList(castParams.FilterDescendantsInstances, maxParts)
		
		print(parts)
	end
end

You could size the part trying to detect what’s near it up by .01 for an instant to see if anything’s touching it in the immediate area.

Try this:

local Parts = --folder

for i,v in ipairs(Parts:GetDescendants()) do
	if v:IsA("BasePart") then
        v.Size = v.Size + Vector3.new(.01,.01,.01)
		local touchingParts = v:GetTouchingParts()
        v.Size = v.Size - Vector3.new(.01,.01,.01)
		for _, part in pairs(touchingParts) do
			print(part)
		end
	end
end
2 Likes

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