Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

How to make y-sorting in RPG games??

A topic by SakshamVerencar created 45 days ago Views: 220 Replies: 4
Viewing posts 1 to 5

I have tried many times to make my character y-sort but it's not working

also, I am using Godot 4.4

thank you for reading this

HOW TO DO Y-SORTING IN GODOT 4.4

1. Basic Node Structure

Make sure your scene follows this structure:

YSort

└── Character (e.g., Node2D or CharacterBody2D)

    └── Sprite2D

    └── CollisionShape2D

IMPORTANT: The node that moves (the character) must be a direct child of the YSort node — not a grandchild.

2. Enable Y-sorting

  • Select the YSort node.

  • In the Inspector, ensure the property sort_enabled is true (enabled by default).

  • Godot will automatically sort all children of the YSort node based on their Y position.

3. Keep the Sprite Centered

Make sure your Sprite2D is centered inside the character node, because Y-sorting works based on the parent node’s global position, not the sprite’s offset.

4. Beware of Z-index Conflicts

Godot 4.4 still uses Z-index (under CanvasItem), and it can override Y-sort behavior if not set correctly.

On your Sprite2D:

  • Set Z-index to 0 or leave it empty.

  • Uncheck Z as Relative.

This ensures the YSort logic takes priority.

What if you have multiple characters?

Easy — just make all of them children of the same YSort node:

YSort

├── Player

├── Tree

├── Enemy

💡 BONUS: Instancing at Runtime

If you spawn characters or enemies at runtime, as long as they are children of the YSort node, they'll be sorted properly without any extra setup.

🔧 SMALL CODE TIP (Only if you want to force the order manually)

Normally not needed with YSort, but you can still manually change z_index:

$Sprite2D.z_index = 1  # Force to render on top (not recommended with YSort)

thank you but what about tilesets?

🧭 TL;DR for Godot 4.4:

If you're using TileMap nodes with tiles from a TileSet, Y-sorting is handled differently now than in Godot 3.x.

Godot 4.4 introduced:

  • A completely overhauled TileMap system

  • Scenes as tiles, layers, and custom properties

  • Automatic or manual Y-sort behavior

🧱 How Y-sorting works with TileSets in Godot 4.4

🧰 Step-by-step setup:

  1. Use a TileMap node (not GridMap).

  2. Assign a TileSet with tiles that have textures or scene references.

  3. In the TileMap properties:

    • ✅ Enable Y-Sort under TileMap > Y-Sort.

    • This tells Godot to draw tiles based on their Y coordinate on screen (lower Y behind, higher Y in front).

  4. Make sure your tiles in the TileSet editor have correct offsets:

    • If a tree is taller than 1 tile, offset the texture so its base aligns with the tile origin.

    • The tile origin is the point Godot uses for sorting.

🧠 Important concepts to get right:

🔹 Origin point = Sorting point

Godot sorts by the tile's visual bottom (the Y offset). If you don’t set that correctly, sorting looks broken.

Tip: For tall sprites like trees or houses, shift the texture up in the tile editor so the base of the object touches the tile origin.

🔹 Using Scenes as Tiles

If you're using scenes (prefabs) as tiles:

  • Your scene root should have a YSort node.

  • The TileMap will instantiate these scenes and Y-sorting will follow that node's position.

🔹 Multiple layers

If you're using TileMap layers (e.g., ground, objects, roofs):

  • You can have multiple TileMap nodes (one per layer), each with Y-sorting enabled.

  • Godot does not automatically sort between layers — you must manage layer Z-indices or draw order manually.

🔥 Bonus: Dynamic characters and Y-sorting

Your player sprite (or enemy, NPC) should be:

  • In a YSort node

  • Positioned in the same Y axis space as your TileMap

  • Then Godot will sort the player in relation to tiles (if all YSort nodes are siblings or in same parent YSort).

✅ What to double-check in Godot 4.4

  • TileMap node has Y-Sort: ON

  • Your tiles in the TileSet have proper offsets and alignment

  • Your visual layers (ground, objects) have proper Z-index if layered separately

  • If using scenes as tiles, their root nodes have YSort

  • Characters exist inside YSort containers and are placed at the same coordinate space as the tilemap

🧪 Want a fast test?

Here’s how to test Y-sorting quickly:

  1. Make two tiles: a grass tile and a tree tile (with transparent top).

  2. In your TileSet, shift the tree tile up by 32px (so the base is centered).

  3. Place the grass and tree tiles on a TileMap with Y-sorting ON.

  4. Move your character (in a YSort) behind and in front of the tree.

  5. Boom — you’ll see it visually sort properly based on Y.

thank you so much I thought I won't get any reply, now i can work on my project peacefully