Detecting Part Colissions

Greetings!

I am currently working on a project which utilizes a grid-based placement system. At the time of writing this, it is possible to overlap as many objects as the player desires. This is obviously an undesired feature of the system. My question is, how can I use something like the touched event to detect colissions between baseparts? As mentioned on the Roblox Dev Hub, the touched event only fires when parts physically collide with each other, and not when their positions or CFrames are being manually modified.

Let me know if you have any suggestions!
Thank you in advance.

From my past experience, using the Touched and TouchEnded events for stuff like this is a complete pain. Consider using WorldRoot:GetPartsInPart() or since you’re implementing a grid placement system, use WorldRoot:GetPartBoundsInBox() which would be more efficient since you’re dealing with cubes.

Hey there, I appreciate your reply!

Maybe I didn’t read far enough, but when using the workspace:ArePartsTouchingOthers() method, is there a way to get a table containing all of the parts that are coming in contact with the parts in the partList table?

Looping threw all the partList table and checking if they are in contact with the other parts

Ex:

For _, part in pairs(partList) do
       -- Your code that checks if they are touching
end

I mean, is there a way to determine the parts that they collide with? Like can I make an ignorelist of some sort?

You can yes if you make a table that contains all the parts that you wish to ignore. You can simply make a if statement that checks if that part isn’t in that ignore table it will check if it’s colliding.

For the touching you can do this

Ex:

for _, part in pairs(partList) do
    local touching = game.Workspace:GetPartsInPart(part)
	for _, v in pairs(touching) do
        if --v isnt in the ignore list then
		-- Return or anything you want to happen to that touching part.
        end
	end
end

This is working great! Just one more question. With the PartsInPart() method, is there a way to customize the overlap? For example, I have a wall object and I need to be able to place two walls directly next to each other, (touching), and it considers them to be colliding with each other.

Well that depends do you want the walls to connect like snap ons or more like they can go threw each other but only a certain distance?

Right now it looks like they may be colliding with each other by something like 0.1 studs, so it considers them to be colliding with other parts.

You could make a dictionary that says what part is considered a wall and then do a if statement checking if it is a wall and touching then make another if statement checking how far the wall is inside the other wall.

How could I write the if statement to detect the overlap? I know how to do the dictionary and such.

I would make a function that calculate their position and size (math) to check if they are too much inside each other. If yes it will return true else return false.

If you don’t know how to make the math calculation I could perhaps find a math solution.

Yeah, I am just unsure of the map for that.

that’s where things get a little complicated because you are checking if two a 3D parts are overlapping.
Sadly this would take time for me to make a example script. So here’s a similar question someone asked that you are looking for.

Hopefully this helps you.