Problem with z_index

Godot Version

4.4.1

Question

Guys, so… I’m currently making this game and it’s similar to Tibia and i’m quite annoyed because the z_index limitation, like when i first started this project i came across the fact that the sprite of my character, wich was closer to “me” relative to the camera and viewport, was actually being rendered behind the enemy that was further to “me” and the camera so i used this code to organize the characters automatically:

for Child in get_children():
if Child is CharacterBody2D:
Child.z_index = floor(Child.global_position.y / 32)

The point is: the z_index can only go between -4096 and 4096 (positive) and i feel limited to this range, and that i will reach the limit at some point. I cant make walls and ceiling the way i want either, because of this.

Have you tried enabling “Y Sort”? It’s what you are doing with the position.y but at an engine-level that likely isn’t as restricted and much faster.