I want to be able to move objects on a grid always by what the grid cell size is, and objects bigger than the grid size should not overlap.
The cube in this GIF below is snapping how I want (1 x 1).
If I then change the size of the object, it doesn't snap to the grid quite how I would like. It snaps, but overlaps. I don't want an object to overlap the grid cell.
The snapping code is pretty straight forward and has been posted quite a lot and seems to work fine.
pos.x = Mathf.Round(hit.point.x + (hitNormal.x * objScale.x)) * gridSize; pos.y = Mathf.Round(hit.point.y + (hitNormal.y * objScale.y)) * gridSize; pos.z = Mathf.Round(hit.point.z + (hitNormal.z * objScale.z)) * gridSize;
I was thinking that I need to somehow set a pivot / anchor point, but I wouldn't want that to be one corner of the object, I was thinking somehow I could find the center of the object and work from there so it can snap correctly. Not sure if this is correct, or how to work that out.