0
\$\begingroup\$

I'm trying to create an isometric tilemap world in Godot 4 beta 4. The world is made of blocks on top of each other where for every Y level (thinking the world like if its in 3D coords) there is a different layer of tilemap.

My player is like 1.5 blocks tall and I want to put it in the world, but I can't understand how to draw the player in the right order with the tilemap to prevent the player going over or under every layer of the tilemap.

Right now every layer except the terrain one is drawn on top of the player like in this image: enter image description here

Expected result: enter image description here

Another example of an expected result:

enter image description here

I also tried making the same thing with threejs before doing it in godot where I can define the order of every object before rendering every frame, so I divided my tilemap by distance from the camera and put the player in the right spot in the rendering order based on its distance from the camera (its like zindex but without changing the actual Z of the sprites, just calculating it from the X and Y coords of the world).

But I don't think there is a way to do this in godot and I have no idea where to start.

The question is, how do I manipulate the rendering order of the tilemap to make the player fit in the right spot? If this is not possible, is there any way to archieve the expected results?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Customizing Draw Order

According to this issue, there is currently no support in Godot for customizing the draw order how you want, but there are some workarounds:

  1. Manually sort your tiles. "TileMaps currently break ties by rendering the oldest tiles first" so you can change the draw order by creating tiles in your intended order.

  2. "changing the second value in the TileMap's cell_custom_transform to a very small number like 0.01 so tiles are rendered from left to right."

This is because the tiles on the left have an indiscernibly smaller y value. This could be changed to -0.01 to render from right to left.

This does mean that your tiles won't be perfectly horizontally aligned, and will drift by a pixel every 100 tiles. But, this small amount of drift may be preferable to the blinking of the xsort() function I provided.

Controlling tall item draw order

Looks like changing the node hierarchy to allow y sorting to sort individual nodes as described in this answer might help for properly sorting your character (who is taller than a single tile).

Essentially, make sure your character is at the same level in the hierarchy as all of the other tilemap nodes (instead of putting all your doors/torches/etc under one node).

Also, make sure the character's root position is at their feet so when their feet are in front of a wall, their whole body is also considered in front of the wall.

then the walls tilemap should sort the wall tiles, the character, and all the torch nodes based on their Y position. Although, I can see a small issue where the Y position of the wall tile matches the wall tile, causing the wall to be on top (maybe). This should be fixable by moving the torch down a little (by 1px or even less).

\$\endgroup\$
3
  • \$\begingroup\$ If I try one of these workarounds, like the second one, the player will continue to be drawn before or after the tilemap... how can I decide when to draw the player? \$\endgroup\$
    – Crih.exe
    Commented Nov 14, 2022 at 7:46
  • 1
    \$\begingroup\$ Oh, I may have misunderstood. Looks like changing the node hierarchy to allow y sorting to sort individual nodes as described in this answer might help? \$\endgroup\$
    – idbrii
    Commented Nov 14, 2022 at 8:48
  • 1
    \$\begingroup\$ @idbrii please update your answer with your comment so others can find your answer helpful \$\endgroup\$ Commented Nov 17, 2022 at 7:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .