I’m just going to drive straight into my problem. I’m working on a building system with boundaries. But, when a part is placed on the side of said boundaries, half of it “clips” outside of the boundary.
At a glance it looks like you’re not taking into account the size of the block. If they are ending up 1/2 way out, subtract 1/2 the part width maybe. I’m assume you also made the boundary based off where the block end up and didn’t just make a boundary, now looking to add blocks.
You should check whether the part placement is valid before placing it there. You can do this by checking whether there are parts or terrain inside your part.
local blockSize = block.Size
local xSize, ySize, zSize = blockSize.X, blockSize.Y, blockSize.Z
print(“X size of the block:”, xSize)
print(“Y size of the block:”, ySize)
print(“Z size of the block:”, zSize)
or more like …
This is x,y and z. Probably don’t need all 3 in this case to be /2.
local block = – your block
local position = – the position it’s going to
local blockSize = block.Size
local xOffset = blockSize.X / 2
local yOffset = blockSize.Y / 2
local zOffset = blockSize.Z / 2
block.Position = position - Vector3.new(xOffset, yOffset, zOffset)
I’m not sure what all you’re doing. But the blocks should fit inside your border flush to start with by whatever amount of movement. You may want to change your boarder a bit.
You said it’s starting dead center, so it is already placed at a 1/2 way point vs size.
Wouldn’t such an offset create even more problems, though? Checking whether a part placement is valid rather than adjusting it seems like the better solution to me, which is why that’s what I always do when creating placement systems.
Plus, you’re only accounting for one boundary, what about other boundaries in different directions? If you try to place it on a boundary facing the other way, the part would be way inside the boundary.