Grid Offset

I shall try to keep my questions singular so you do not have to read!

What is the intention of having a default offset of 0.5 on grid axes?

If I make a game object that is one cell size based on the sprite’s ppu, and center it at world origin (0,0,0), it’s at a position where four grid cells meet.

Don’t get me wrong, this is not a complaint, I’m just curious as to what the purpose behind the design is.

How I long for the days where simple questions would become exploration and learning exercises in which we discovered things. :stuck_out_tongue:

The visual placement of sprite will depend on it’s pivot which you can define in sprite import settings and sprite editor.

If the pivot is in the middle of sprite (which might be the default but I didn’t check that) it will behave like you described. There isn’t really any offset. The purpose is that it allows you to get the expected result when you place multiple sprites in the same position. Imagine if you had two sprites one 1 unit big and one 4 unit, with the behavior described above when placing them in the same coordinates the smaller one will be in the center of bigger one. It often also makes measuring distance simpler since you will often want the distance between centers, not distance between some specific corners.

But not all the games are the same if it would be more convenient in your game to position based on sprite corner instead of center you can set the pivot there. A common case to change the pivot position is games with isometric or other similar view, in such games it helps to position pivot at the bottom of sprite and configuring unity to sort sprites by pivot position.

Few more cases when you might want to change pivot position:

If you are making a grid based game it can sometimes (but not always) be easier to place pivot in corner.

If you are making a pixelart game, it may be to put pivot in a corner or at least in a position that isn’t in the middle of pixel. Doesn’t make a difference for sprites with even dimensions (for example 20x20) since their center is between pixels anyway. But if you have something like 21x21 or even 20x21 having pivot in the middle it may cause some issues.

On the other hand if you are rotating the sprite in most cases you will want pivot in the center. For more complex sprites you might rotating around a specific point, but that will depend on the content of each individual sprite.

Regular tile is 1x1 unit, so 0.5x0.5 offset is its middle. It is used for example in CellToWorld function, so if you have coordinates of cell x:20,y:30 you can get the middle of the cell in world coordinates, to move Pawn there for example. Cell coordinates are Vector3Int and World coordinates are Vector3 (float).

The opposite function is clicking the mouse on the tile, you get screen coordinates, you translate them to world coordinates, and next you can translate them to cell position with WorldToCell.

No idea if the grid in original question referred to the Grid component the one often used in combination with tilemaps or coordinate grid in general that’s also drawn in the background of scene view. My answers assumed mostly plain SpriteRenderer and how they relate to coordinate grid.

That actually makes total sense now that you guys explain it, why on earth would I want my cell positions at (x.5, y.5)?

It just seemed counter-intuitive at first when I placed my game object at world origin and was a little confusion.
But who says it needs to be at (0, 0, 0)?

Oh well, back to spending hours converting my 3d game into a 2d game, redoing work I’ve already done, and praying android can handle it.

(That’s right, I wanted to make a 3d android game. Many people talked me out of it.)

[This is of course not the game, just some general visualizations setup for understanding]

dunno why u say u cant make a 3dgame for mobile, look for example genshin impact on mobile

I’m not sure that I can’t, I honestly really wanted to. The thing is, I’m working on a tower defense and I went and checked out the competition and all the top-10 tower defense genre games were 2d so instead of assuming they’re taking the easy way out (which was my original thought, as 3d is a tad bit more complex), I decided they knew things I did not because their games were very impressive. If nothing else it leaves more clock cycles for doing other interesting things.

Bell Labs-Esque Style. “Do Interesting Things” <3