ilia_here
ilia_here

Reputation: 33

How to make the character draw correctly in relation to objects, being on different sides from them on Godot?

Using tile maps is pretty convenient, but there is one drawback. All tiles are on the same layer. This does not allow performing some operations with graphics, as, for example, in my case I need that when my character is in front of some tile (wall), his sprite is drawn in front, and when in the back, vice versa. This can be achieved by changing the position of the tilemap layer, but then only one tile will be drawn correctly. The tiles on the other side of the character will be drawn at the same level. How can the problem be solved?

Upvotes: 1

Views: 847

Answers (1)

JarWarren
JarWarren

Reputation: 1549

Add a YSort node to your scene and place your player inside of it. The YSort arranges nodes so that the lower they are on the screen, the closer they are to it.

For example, if my player were below a fence, he would stand in front. If he were above the fence, he would be drawn behind it.

This video displays the effect you're going for, using autotile and YSort together https://www.youtube.com/watch?v=RPgTlxb7Bno.

Upvotes: 0

Related Questions