Hi,
Using the new tilemap system (isometric tiles), I use getcellcenterworld so that my gameobjects appear standing in the center of each cell.
As of now I only have one tilemap at coordinates 0,0,0 as I don’t intend to use obstacles/floors yet.
The sprite I use has its pivot at bottom center.
Unfortunately, it seems tilemap.getcellcenterworld places my object at the bottom of the cell, but if I use the parent grid.getcellcenterworld, my gameobject is placed correctly at the center of the cell.
tilemap.getcellcenterworld
grid.getcellcenterworld
using debug.log on the same cell I get:
(-1.5, -0.3, 0.0) for tilemap.getcellcenterworld(cell)
(-1.5, 0.0, 0.5) for grid.getcellcenterworld(cell)
I’ve tried changing tilemap z transform to 0.5 and it doesn’t seem to have any effect (which is logical as I’m not using Z as Y).
Please note I’m a novice in Unity and trying to figure out the workflow of things.
I haven’t found any thread anywhere talking about a similar issue, I hope someone has an idea what I could’ve done wrong (or maybe the tilemap system still has bugs?).
Bonus question: tilemap.cellbounds returns wrong values for xmax and ymax (1 cell too big) even after compressing tilemap bounds. Any idea where that might come from? Is that a bug?
Grid.GetCellCenterWorld uses the center of the Isometric cell as the cell center while Tilemap.GetCellCenterWorld uses the Tile Anchor value as the center center (which looks like it is set to 0,0,0?).
That would be weird! Tilemap.cellBounds returns the origin and size of the Tilemap as painted on, which could be larger if Tiles were erased from the Tilemap and Tilemap.CompressBounds was not called. Xmax would likely be origin.x + size.x. Could you share the values for these in your Tilemap, as well as the extent coordinates of Tiles set in your Tilemap? Thanks!
Thanks a lot! I totally forgot about tile anchor, You’re a lifesaver.
I have corrected my tile asset, set my Tilemap’s Tile Anchor to match grid and now everything is good!..
Except the cellBounds which have not changed!
Here is what i get debugging each bound:
xMin = -4 xMax = 6 yMin = -3 yMax = 3
And the values I get by returning worldtocell on mouse position on each corner with a tilemap.HasTile check (just to be sure it’s in bounds):
(-4, -3, 0)
(5, -3, 0)
(5, 2, 0)
(-4, 2, 0)
Ah, I think I get what you mean. The “max” property of the BoundsInt (cellBounds is a BoundsInt) returns the maximal point, which would be the end of each dimension of the last cell.
In your case, the maximal x cell for your example is 5, so the max value would include the length of the cell (1), which would be 5 + 1 giving 6.