The arrival of the Tilemap is beyond awesome. I’ve been playing around with it and diving into the API. However, to draw the player in-front-of or behind GameObjects was simple before with a simple sorting script; checking the location of the player, the location of the sprite and setting the sort order on the SpriteRender depending on y-values.
However, it seems that is not possible for individual tiles in a Tilemap, only for the entire layer.
How would I go about and sort the drawing order of tiles depending on the players location? Any tips? Can it be done with the Tilemap or is there perhaps a better way to sort?
If a tilemap is set to “individual” instead of “chunk,” each tile is sorted individually for me.
However, in a top-down game, the issue is that a tower, for example, is composed of several tiles, and if you’re behind it, they all sort individually, not as one cohesive tower. You will thus be behind some of the tower’s tiles while also in front of some other tiles.
I think that the only solution now is to use two different layers of tiles that cover (like the tower’s top) and tiles that the player/NPC covers (like the tower’s base).
Unity should implement a better solution however. My suggestion is to have tiles behave cohesively if selecting a group of them (and possibly checking a bool box like ‘sort whole selection’ within the tilemap). This way, the bottom tile’s bottom acts as the minimum y threshold.