Orthogonal View: snapping objects to grid at runtime

Hi Guys!

I’m looking for suggestions of how to create a grid, snap instantiated objects to that grid during runtime.

I’m using orthogonal camera.

Ideas are welcome!

Maybe something like this:

float snap_resolution;

float x_snapped = x + (snap_resolution * 0.5f);
x_snapped -= (x_snapped % snap_resolution);

float z_snapped = z + (snap_resolution * 0.5f);
z_snapped -= (z_snapped % snap_resolution);