I am wanting to offset this block to the next available grid position, which works with slabs, but if I have a part that isnt as thick as a slab, it doesn’t work right.
PartPosition is the position of the part my mouse is over. GRID_SIZE = 3 and normal is the normal of the part I on. Looking in particular at the top half.
if math.floor(part.Position.Y - 0.75) % 3 == 0 then -- Top half
return PartPosition + (normal * GRID_SIZE) + Vector3.new(0, GRID_SIZE, 0)
else -- Bottom half block
return PartPosition + (normal * GRID_SIZE) + Vector3.new(0, GRID_SIZE, 0)
end
If I remove the + Vector3.new(0, GRID_SIZE, 0) it works with the red part, but then places the block inside the slab for slab blocks.
Both slab and red block are placed at the top of a grid space, they just different thickness’ So ideally the code should be able to just figure out the next available slot
local function Snap(GridSize,POS)
local X = math.round((POS.X/GridSize + 0.5)*GridSize)
local Y = math.round((POS.Y/GridSize + 0.5)*GridSize)
local Z = math.round((POS.Z/GridSize + 0.5)*GridSize)
return Vector3.new(X,Y,Z)
end
Snap(GridSize,Position) -- replace GridSize with yo GridSize and Position with yo position
Sorry to continue this pointless conversation but for the slab couldn’t you just put an invisible cube to offset it by, then you could skip all the extra math and just do the classic method with the invisible cube that’s hopefully welded to the slab.