Snapping in increments

I’m attempting to make a lego game and I want to be able to move the lego bricks around on an increment just like the “snap during transform” tool in blender. Currently, I have the x and y scale of the (single) brick I tested with 1x1. The brick is on the second layer and will be added to the int position of where the mouse hits. This sort of works for that specific brick but only that specific brick because there are many different shapes and sizes of lego. Is there any way to snap an object to a grid?

Blend file

what you need is snap to grid, and snap to socket from there.

so aiming at the ground, it places a sensor object that is the shape of the placed item currently selected, if the sensor does not collide, place the brick, from there, if you aim at a socket on a placed block, it orients and places a sensor based on the ‘jacks’ of the block, no collisions? place block in socket.

you will need a method to rotate pieces around based on the socket availible, to be able to decide how to place, if the object needs to move, have a compound
root object all pieces that will move together are parented to, making it so you only need 1 collision sensor for all the cubes involved in the vehicle etc.

if you need to workout what block is hit, you sort the blocks by distance from hitpoint of ray, closest child object is the one you hit*

for childen rootObject.children:

sortedList = (use python sort function to sort by the second value of list)


You do not need to snap. Just ensure you move them in fixed steps and rotate in 90° steps. This ensures you always stay on grid.

Snapping requires position and orientation correction via Python.