Placement system - how do I check if there are 4 blocks available as a foundation

Hey, I’m making a placement (building) system.
For now, each item can be placed on 1 block (foundation).

The code I made:

local surface = Mouse.TargetSurface
local modelSize = targetModel:GetExtentsSize()
local modelCenter = targetModel:GetBoundingBox()

-- placeability checks here

surface = surface.Name

local vecCorrection = 
	surface == 'Top' and, modelSize.Y , 0) or
	surface == 'Bottom' and, -modelSize.Y, 0) or
	surface == 'Right' and, 0, 0) or
	surface == 'Left' and, 0, 0) or
	surface == 'Front' and, 0, -modelSize.Z) or
	surface == 'Back' and, 0, modelSize.Z)
selectedItemModel:PivotTo((modelCenter + vecCorrection) * CFrame.Angles(0, math.rad(currentItemRotation), 0))

However, this basic placement system is not enough for some of the items.
There are items that are too big for only 1 block.
Here’s an example of what I mean:

What I want to achieve is to have a bigger grid for some of the items, if that makes sense.
So, if I picked a big item, I want the grid to look like so:


And then, if I hover my mouse on any of the blocks in the group, it should automatically set the item position to the center point of the group:


Sadly, I don’t have any idea how to go about detecting the groups.
Spatial queries could be an option but then the groups would mix up.
I would appreciate any help! :slight_smile:

You’ll want to set a main hitbox or part as the PrimaryPart of the model to use for positioning. The size should be the same as the space you want it to fit. Then you can round the position by the size of each square. You’ll also want a hitbox for the entire model and run GetPartsInPart on it, with exclusions for anything inside the model.

I considered using spatial queries but then, how would I detect where’s the center point of the group?

You have to do that yourself by using a part as the PrimaryPart of the model. Either that or average all of the positions of each part in the model, but the former has more control.

Well, the problem is that I want the item to automatically move to the center point of the group after I hover my mouse on any of the cubes in the group.
So, these groups have to be defined somehow or detected.

Checking if there’s enough blocks to place the item would be easy but I need to move the item and that’s the part I have a problem with

What part are you exactly having an issue with? I see that it’s positioning to each individual square, so why not offset it by half the size of the square? Either that or just round everything to a grid placement.