Thank you for reply! :)
Could you please explain what YSort node does here? What is the logic?
All children of a YSort node will be displayed in a particular order, based on their y positions. Child nodes with a higher y position will appear on top of nodes with a lower y position. So rather than using Godot's default "Z index", or level hierarchy to determine what goes on top of something else, it's using the y position of each object - things lower on the screen will be in front!
So when the player's origin point is below the box's origin point, that means the player should appear in front of the boxes. Once you move the player up so that their origin point is above the boxes' origin point, the boxes will be drawn on top instead.
Note that for this type of game, each object's origin point should be set to "bottom", at the point where they "touch the ground". Having it set in the middle of the object can lead to weird results.