How do I get a nice approach to creating and aligning tiles? I presumably have a perfect 1x1 prefab, since that is what my mesh claims to be.
I’m looking for perfect tile origin coordinate offsets, e.g. (1.0, 1.0), (2.0, 1.0)? I would like to be able to use both grid snap and vertex snap interchangably, though I’ll resign to one or the other if I must. The tiles are box colliders, so they can’t have a gap that will cause problems with typical CharacterConroller and rigidbody solutions, though overlap may be permissible.
In my experiments, I always end up with an apparent drifting floating point precision error. So, a long row of grid snapped tiles diverge from vertex snapped tiles, which diverges from perfect coordinates. If I mix and match use of grid snap and vertex snap, I’ll get blocks that don’t align. Is there a way to keep blocks on the grid by using vertex snap?
Hello, it is done with general maths, if you want each tile to be one unit, you make a loop on X and Y so that every tile is in between on position 0.5, 1.5, 2.5… that is perfect precision it is as easy as that.
var size= 20;
for (var z = 0; z < size ; z++)
for (var x = 0; x < size ; x++)
{
instantiate(tile object, Vector3(x+.5,0,z+.5), Quaternion.identity);
}
if you are doing blocks/bricks walls using bouncing physics, you may find you need to space them by a tiny amount otherwise it will think they corners are in the same place and will bounce them.
Thanks for the idea. I think this would work for programmatic tile placement. My challenge is to have a pipeline in the Unity editor where I can use the grid snap (Ctrl + drag a translate axis) and vertex snap (V, select a vertex + drag to another vertex), and it still remains coordinate perfect. Much of my content will be hand-edited. That's why I'm caught up on this tricky pipeline. Thank you again for the good idea.
So, I played with an editor script for object drag and drop that forced a grid snap posted here.
But, ultimately, I concluded that this was unnecessary for my purposes. I abandoned the vertex snap approach, which introduced an accumulating floating-point precision issue with my cubes. Instead, I’m using both Ctrl + axis drag on selections and Ctrl + plane drag (when I only want to restrict it two two axes). Now, all of my cubes stay on intended transform position multiples, but I can layout and manipulate fast with duplicate and drag.
if you are doing blocks/bricks walls using bouncing physics, you may find you need to space them by a tiny amount otherwise it will think they corners are in the same place and will bounce them.
– MountDoomTeamThanks for the idea. I think this would work for programmatic tile placement. My challenge is to have a pipeline in the Unity editor where I can use the grid snap (Ctrl + drag a translate axis) and vertex snap (V, select a vertex + drag to another vertex), and it still remains coordinate perfect. Much of my content will be hand-edited. That's why I'm caught up on this tricky pipeline. Thank you again for the good idea.
– s_guyyou may find for the moment that clicking on the position of the tile and pressing 1.5 tab 1.5 tab 1.5 etc can be faster than using the cursor.
– MountDoomTeam