- Home /
Can I get perfect 2d tile alignment using grid snap AND vertex snap on 1x1x1 unit cubes??
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?
Thanks!
Answer by s_guy · May 03, 2013 at 05:55 AM
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.
Answer by MountDoomTeam · Apr 20, 2013 at 06:40 AM
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.
$$anonymous$$y 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.
$$anonymous$$uch 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.
you 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.
Your answer
Follow this Question
Related Questions
Clear, Crisp pixel textures for a 2D RPG 2 Answers
How to create 2D pixel water shader ? 0 Answers
2D Animation does not start 1 Answer
How to make shadows in Top Down 2D game 1 Answer
Is it possible to zoom in or out with the pixel perfect camera? 0 Answers