What's the best way to detect if a CanCollide block is colliding with another block?

I want the most effecient way to detect block collisions (blocks inside of other blocks)

As you can see, when I try to place a grass block, it appears even tho theres a slab in that spot (intersecting)

I was gonna use either :GetTouchingParts() or .Touched, however both have their flaws. In particular that they may be too taxing (being called every RenderStepped) or that they will return results in blocks are adjacent. I only want something to fire if there is directly a block in it

I am running this from RenderStepped, so it needs to thus not be taxing on the client.

3 Likes

Is this a grid based system? The easiest way would be to just keep track of all your placements in some data structure, and rather than checking parts you just lookup in your data structure “did I already place something here?”.

Ye, that’s what I’ve started to try attempting, however there’s problems with that, like 2 slabs can be be placed in the same “3x3x3” cube area, as those 2 slabs make up 1/2 a full block.

So like my instance there, I need it to detect that since you trying to place a full block in a spot that only a slab can fit in, it should prevent that. A slab however should be allowed to place in that position

You could use Region3 to determine if there are multiple parts in a certain region:

If double slabs are the most complex case, I would still use a grid system, and just allow cases where two slabs can occupy the same space.

Minecraft for instance uses a separate block ID for a double slab. That full block replaces the existing slab when you place a second slab.

I’m gonna allow for seperate slab types being placeable in the same block space tho

If you really want to detect touching parts just use GetTouchingParts() function but I might be wrong beacuse I’m not using this too usually. But there’s the other solution beacuse you can use module or table to check if this grid is free or not and get size of block you want to place and divide it on grid size so you get it’s size in grid numbers