#Y-Sorting Issue: Tilemap goes above player / player disappears after crossing the y-axis

12 messages · Page 1 of 1 (latest)

ancient bane
#

Demonstration of the issue: https://i.gyazo.com/c029a31d25ec63f924b99fa53831092a.mp4

Pretty sure this is a common issue but I don't know what to do </3
Essentially, I have a tilemap that extends upwards beyond the y-axis (y = 0) and whenever my player crosses the y-axis, it disappears. I believe this is an issue with tilemap y-sorting and the grass/water tilemap's position is above the players or something like that, but I don't know what to do to fix it. I've attached screenshots of the node trees here.
(Note: main_scene.tscn (first screenshot), level_1.tscn (second screenshot) and level_2.tscn (third screenshot) are all different scenes)

What I've tried already:
I've tried debugging with this link: https://forum.godotengine.org/t/player-randomly-dissapearing-in-game/90999/9 as it appears they were facing the same issue. The answer given was "You have Y sort enabled on the root node, so the tilemap is placed above the player because it’s y value (at 0, 0) is above the player’s. I believe you only want Y Sort on the tile map layers."

  • ...except when I disabled y sort on the GameTileMap node and Level2 node (I also tried just disabling it on Level2 and keeping it on for GameTileMap, and vice versa), all that happened was the player was just fully hidden beneath the two tilemaps

I've also seen this one: https://www.reddit.com/r/godot/comments/ss38x6/character_disappears_when_walking_into_a_certain/
which basically suggests the same thing.

  • I've also tried going to main_scene.tscn and turning off y-sort for GameRoot or LevelRoot or both or none, but none of them work.

Currently, I have:
In main_scene.tscn:

  • Y-sort checked: GameRoot, Player, LevelRoot, Level1, Level2
    In level_1.tscn:
  • Y-sort checked: Level1, GameTileMap, Overgrowth, Objects
  • Y-sort unchecked: Water, Grass, Undergrowth
    In level_2.tscn:
  • Y-sort checked: Level2, GameTileMap, Overgrowth, Objects
  • Y-sort unchecked: Water, Grass, Undergrowth
ripe night
# ancient bane Demonstration of the issue: https://i.gyazo.com/c029a31d25ec63f924b99fa53831092a...

without y-sort enabled every thing will be drawn in the order of the scene tree (the lower objects being drawn last so they will appear on top).
you separating the player from the levels means that using that system it can only be drawn fully on top or below all the content of the level. And when enabling y-sort it will also sort the layers you don't have y-sort enabled based on their origin like you already described. Unless you are also using the z-index to adjust that order. If you keep them separated this is pretty much your only option.

The general approach is to only enable y-sort on the relevant tilemaplayers and keep it disabled on their parent node. then add the nodes that also are supposed to be part of that y-sort as children of that layer. that way you don't have to use z-index for the ordering. Plus it should also make the y-sorting more performant, as there is much less nodes to sort (although i don't know if it would actually make a big difference).

ancient bane
# ripe night without y-sort enabled every thing will be drawn in the order of the scene tree ...

thank you for the explanation! could i confirm a few things because i'm a little confused still?

from your first paragraph, i assume i should have the player node be attached to each level node (e.g. the Level1 parent in level_1.tscn would have a child node of Player) instead of having Player be a separate node that's only connected to the levels in the main_scene.tscn? when i tried this out, the camera became static and did not move along with the player -- i'm not sure if this is a problem separate from the original or not (?) (iirc i don't have a camera2d node either on this... so i'm a little lost)

only enable y-sort on the relevant tilemaplayers and keep it disabled on their parent node
i assume this means that any non-TileMapLayer nodes (that are parent nodes of the TileMapLayers) should not have y-sort enabled? when i disabled y-sort on all the parent nodes, it still didn't work. is there something i might be missing?

z-index
everything's z-index is set to 0 here!

add the nodes that are supposed to be part of that y-sort as children of that layer
could i ask if you could elaborate more on what you mean by this? add nodes that are supposed to be part of that y-sort, as in the player? or the tilemap objects? and by children of that layer, do you mean the children of the TileMapLayer's parents (and thus the TileMapLayer's siblings) or the children of the TileMapLayers?

ripe night
# ancient bane thank you for the explanation! could i confirm a few things because i'm a little...

That part with the camera becoming static sounds weird, and like you suspect a problem in of itself. but if you say you don't even have a camera node, then it should always be static, unless you are actually moving the level instead of the character (which i guess would explain it only being static if the player is a child of the level, as it will then just move with it).

when i said only having y-sort enabled on the relevant layers i also stated that objects that are supposed to also be included in the y-sort have to be child nodes of that layer. it's kinda just an expansion on what i said about the player not being separate of the level but inside of it (in Node Tree terms). Although i did now notice that you have multiple Tilemaplayers with y-sort enabled, so if you want them all to sort together, including the player, it would have to look something like this:

GameTileMap
    Water
    Grass
    Undergrowth
    YSort (Node2D with y-sort enabled)
        Overgrowth (y-sort enabled)
        Objects (y-sort enabled)
        Player

That way all the objects you want to y-sort are part of the same sorting, and since the common YSort parent is at the bottom of the Tile-map stack, it will always be on top of the other layers you don't want to sort.

But now coming to z-index. SceneTree order or Ysort will dictate the draw order of objects with the same z-index. Ones with a higher z-index will always be drawn on top of ones with a lower one. So if you give each layer its own z-index in the correct order, you can make sure the y-sort works properly no matter the SceneTree structure, meaning you could keep your player separate.

ancient bane
# ripe night That part with the camera becoming static sounds weird, and like you suspect a p...

thank you for this explanation! i apologize for all the questions -- i'm still unfortunately encountering an issue with this setup

I have it like this now, with "Overgrowth" "Objects" and "Player" having Y-Sort disabled and the "Y-Sort" Node2D with y-sort enabled. the parent nodes (GameTileMap node2D and Level1 node2D) are both y-sort disabled

however, now, y-sort just... doesn't work as intended? here's what i mean: https://i.gyazo.com/d9a62a09170ad5b62b44d1bbd8442908.mp4

that's why i'm a little confused as to why setting the parent nodes to be y-sort disabled and the tilemaps to have y-sort enabled is supposed to work...? because it never seemed to work for me, and no combination of y-sort in the parent and child nodes seems to have the desired effect (my player either goes all the way under the tilemap or is just completely over it)

ancient bane
# ripe night That part with the camera becoming static sounds weird, and like you suspect a p...

oh right- i forgot to mention i've been using this tutorial: https://youtu.be/it0lsREGdmc?si=14N200Gqz5vsL5WB

and this is their github code: https://github.com/rapidvectors/tutorial-components-and-scripts/blob/main/tutorials/croptails/scripts/scenes/characters/player/player.gd

my setup is basically the same as theirs, with the same scripts and everything (i just have different sprites)

ignore the static camera thing i realized i was stupid it was fixed by just adding a camera node

ripe night
ancient bane
#

wait that worked

#

thank you so much

#

i really appreciate this so much wtf thank you!! that fixed it 🙏🙏

ancient bane
# ripe night you have to enable y-sort on the tilemaplayers as well. they are a bit special i...

hi! i'm so sorry but could i ask for your help again? if you don't have time nws!

i found that having the player included in each level scene (Level1, Level2) means that the plant components and the houses are all above the player, which can lead to some issues (shown below):

https://i.gyazo.com/56b3d8bb2c72f3cb21531ae13943aa05.mp4
https://i.gyazo.com/f62e1937dde2aaead22d2357ec283d5a.mp4

the image is what the tree looks like -- the "Cropfields" node is the node that enables the actual crops to be planted

i've tried to disable y-sort on the node2d for cows and chickens (cows & chickens have the exact same setup, just with different sprites) and enable y-sort on each individual NonPlayableCharacter, and also tried to enable y-sort on all, etc. etc. -- the result's always the same. i tried the same thing with the houses, yet it doesn't seem to work.

is this fixable with y-sort? or like... would you happen to know how to fix this </3

ripe night