The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+2 votes

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
in Engine by (20 points)
edited by

3 Answers

+3 votes

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.

by (10,634 points)

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

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?

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 :/
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

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.

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

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

0 votes

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.

by (18 points)
0 votes

You have to adjust the tex offset in tile set.
And node arrangement should be
YSort
- Tile map
- Kinematic body

by (208 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.