How to YSort Kinematic Body and Tilemap?

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

I’m at my wits end, i simply can’t figure out how to apply YSort to the Player (Kinematic Body2D) and Tilemap. I have no problem YSort-ing multiple Tilemap nodes, and Sprites, but not together. I just want my character to be able to walk behind a Tilemap object. Or is that not possible? Do I have to create new Sprite node for every object that the player can walk behind, and put it all together with the player under a YSort node?

Thanks in advance !

Edit:
There might be an issue with the KinematicBody2D node, because when i tried putting the tilemap and a new sprite node under YSort, it worked. My KinematicBody2D doesn’t have a sprite, but comprised of many polygonshape2D because I’m using skeleton animation. That might be the problem?

Edit 2:
Now i tried it to put that sprite inside a kinematicbody2d and it doesn’t work anymore.

so if like this, it worked:

  • YSort
    - Tilemap
    - Sprite

if like this, it doesn’t:

  • YSort
    - Tilemap
    - KinematicBody2D
    - Sprite
:bust_in_silhouette: Reply From: njamster

Your tree should look like this:

- YSort
  - KinematicBody2D
    - Sprite
    - ...
  - TileMap

Make sure the “Y Sort”-property of the TIleMap (in the “Cell”-category of the inspector) is set to true. Then your character should be able to walk behind the tiles.

I tried that first, and it didn’t work. Tried it again exactly like that, still doesn’t work :confused: even try to make the kinematicbody2D local, still nope.

thatreshaad | 2020-03-30 12:42

Well, it works for me! Did you try it in an fresh project? Or does it just not work in one specific project of yours? Maybe you can upload an example project?

njamster | 2020-03-30 18:21

i kinda figured it out, i think its just as simple as how my sprite is not centered to the kinematicbody2D haha. Fixed it, and it sorta works now, buuuut somehow with some tiles it doesn’t.

here it works!

it works with this couch
but here, he’s floating behind a fridge :confused:
but now he's floating behind a fridge

Is there anyway to manually select an area of how far down through the tile till its considered in front of it? if that even make any sense

thatreshaad | 2020-03-31 09:09

Is there anyway to manually select an area of how far down through the tile till its considered in front of it?

Nothing I’m aware of. It simply compares the y-position of the KinematicBody2D’s origin and the y-position of each individual tile’s origin (or the origin of the TileMap, if its “Y Sort”-option isn’t enabled) to determine what’s drawn when.

njamster | 2020-03-31 09:51

Try to play around with attribute Tile Originof the Tilemap node. Default is Top Left, but I found out Center works best for me.

BananaBread | 2021-05-28 00:04

Try to move sprite and collisionShape2D of Player inside the Kinematic (check the center of kinematicBody) to find a better sort

zigstardust | 2021-06-24 22:33

:bust_in_silhouette: Reply From: karaboon

I know i’m a bit late to the discussion, but i had the same problem and solved it by setting the z index of the player to -1, after activating y-sort on the TileMap. Weird, i know. So for anyone who was led to this thread by google too, here is my solution.

:bust_in_silhouette: Reply From: Skydome

You have to adjust the tex offset in tile set.
And node arrangement should be
YSort

  • Tile map
  • Kinematic body