Snap object to grid

How to Snap Object to grid? I mean, if I create object, it will snap to grid. (Yep, minecraft style)

You get the location you want to place something as usual (via the mouse hit location or whatever other method you use) and then determine in which grid part it is.

Just write a macro to do this. It’s fairly straight forward. Get the point you have, divide it by the size of your grid, round the result float to an integer and then multiply that with your grid size again. Do this for X and Y. If you want to include Z you might want to add before doing that a little bit on top of it because the hit location will most likely be between your current grid cell and the one you want to place it (if your objects are exactly one grid large).

Also if you want to do something minecraft styled you might want to check out the “BrickGame” plugin by Andrew Schneidecker. It’s taking care of quite a few issues you would run into eventually. Here’s a link to it:

Cheers

I just need some light on how I do snap to Z when coliding, and then get back to normal when not colliding. Any hint on that?