Mouse offset grid snapping

I’m trying to make a grid-based building system with floors and walls.
The wall nodes align to a grid when placing, the mouse snaps to this grid.
The issue I’m facing is trying to get the mouse to snap to the centre of grid squares (floors) instead of the corners (walls).

This is the function used to align the wall corners to a grid.

local function round(vector)
	return Vector3.new( 
		math.floor(vector.X/grid+.5)*grid, 
		vector.Y, 
		math.floor(vector.Z/grid+.5)*grid
	) 
end

I’m looking for a similar function to round the mouse’s 3d position to an offset grid so that floor tiles can be placed in the middle of 4 walls in a square.

I’ve tried many modifications to that function with no success.
Even ChatGPT couldn’t work it out.

1 Like