0 votes

Hi! So I'm making a 2d top down game and I have an issue with walls.

I need to make it so if the player is standing 'in front' of the wall he will be rendered on top, and if player is 'behind' the wall he will be rendered below.

I know there's a way by making the player a child of the Tilemap and setting Y-Sort to true, but this would break the structure of my game. I will be instancing different tilemaps on runtime and I can't have the player as a child to all of them...

How would you go about making this? Any ideas?
YSort
Of course what I DON'T want to happen is what you see on the picture below.

Thanks for your time!

in Engine by (26 points)

Try using YSort Node and make Player and walls TileMap children of it. Not sure if will work.

I just tried!

Sadly it doesn't work, the Y-Sort just compares the TileMap position (not it's children) to the player's position. So all the walls can be either in front or below the player, it does not check it on a wall-to-wall basis.

Thanks for your suggestion!

Then only solution seems to be to dynamically (at runtime) reparent Player node. Dont make Player by default child of any TileMap, instead parent it to current TileMap (find some method to parent it if you have many TileMaps in one scene - e.g. is Player inside of a rectangle of tile map, if you have only one TileMap per level then things are easy). See this post for reparenting at runtime: https://godotengine.org/qa/9806/reparent-node-at-runtime

Yes, after searching and trying a few things this seems to be the best approach. I really don't like it but for now I'll just stick to whatever works as expected :)

Thanks for your answer!

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.