How should I implement object placement in a top-down 2D game?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By exokem

My first attempt to implement objects involved a tilemap, adding single-tile objects. The primary issue I have encountered relates to how those objects are y-sorted with the player:
Background: I have a player whose collision box occupies one tile, but whose sprite is larger than that single tile. I also have a tree sprite which occupies a 2 wide by 3 high tile area and has a two tile wide collision box at its base. The player should be able to move behind the tree and appear behind it, and appear in front when in front of it.
The issue: When the player is standing below the top row of tiles of the tree object (which I have presently created and added to the game using a tilemap, single tile object), it is displayed in front of the tree when it should be behind it.

The player in the middle two tiles of the tree: Imgur: The magic of the Internet

When the player is in the top two tiles of the tree or in front of the tree, it displays correctly. At present, I believe that this is caused by the tilemap’s default selection of the top left tile of a single tile object as its origin tile, while in this case it would make more sense for it to be the bottom left tile.
I am not sure precisely how to resolve this or if there are other approaches that could be equally effective.
I have tried using a YSort node and swapping the hierarchy of my player/tilemap nodes without success. Changing the tilemap tile origin does not work, as it seems to only refer to the origin tile and not the object as a whole.

What I did for something similar was to split the tree into two parts, top and bottom, and place them in two different tilemaps, one of which was above the player node in the hierarchy, and one of which was below the player character in the hierarchy to control the draw order.

exuin | 2020-09-25 03:18

That sounds like it would work reasonably well, but it would make actually placing the objects a bit more time consuming, especially if I am going to place a ton of trees or something. Kind of strange that it’s not intuitively possible to get multi-tile objects working within a single tilemap.

exokem | 2020-09-25 03:25

I only made trees that the player would get near two parts. Trees out of bounds would just be one part.

exuin | 2020-09-25 05:29