Currently I have got the grid of grid squares being generated correctly as you can see from the image below. The grid is made up of a series of planes.
The way it currently works is if I click on a grid square I will instantiate a cube and snap it to the center of the grid square. This works perfectly fine when the cube is the same size as a grid square as you can see below.
The problem occurs when trying to instantiate objects that are bigger than one grid square. For example if i instantiate a 3x3 cube at one of the edge grid squares it will overlap and part of it will be off the edge of the grid. You can see this problem below:
Instead of using the centre of the grid to position the cube you need to make it more dynamic so it’ll handle any size of cube.
For example, take the top-left hand point of the selected grid point and then add half the cube’s width to the x position and half the cube’s height to the z position. That way it’ll be central if the cube is 1x1 and aligned properly even if the cube is 3x3.
I think it depends on how you want it to act, each of your cubes would have to have a width and height that’s a multiple of your grid size. If you place a cube at the bottom right of the grid you might want to line it up differently etc…
Your behavior is too ambiguous. The first step is determining whether or not the cube can actually fit on the grid at the given cell. The second part of that is determining how it should try to fit. For example, if the cube is 2 cells wide and I click on the first column of cells should it use the “left” part of the cube or the “right” part. Having a center for cubes with an odd number of cells as their height and width is easy, it gets trickier beyond that.
You’re asking for a silver bullet solution when the better path is to break the problem down into smaller parts and solve them one at a time.