Sprite Rendering Order Issue (545778)

Hello everyone,

Info

I am making a game similar to Don’t Starve graphic-wise (Bill boarded 2D sprites inside a 3D environment) (Picture)

However I am using an orthographic camera as opposed to perspective with a 45 degree rotation around x-axis

The Problem

I noticed that some small sprites appear behind bigger ones even if they are positioned in front of them. After some research, I found out that Unity renders sprites based on the distance between the camera and CENTER of the sprite, therefore, with my camera setup, taller sprites will have centers that are closer to the camera. That is why this does not happen with objects that are the same height.

My theoretical solution is to tell Unity to order sprites only based on their z position. That would work best but I do not know how to do that (in an efficient way). Any ideas?

My one (probably bad) idea was to set the sprites’ sortingOrders to their z position times like 1000. I just do not find that clean and I am not sure what effect it has on the performance, therefore it will be my last resort.

Thank you in advance! :slight_smile:

Anyone? This problem is really annoying me :frowning:
I’ve posted this over Answers already but haven’t got a helpful response

as you said unity is sorting prites based on the distance between the camera and CENTER of the sprite.

what you can do is to make a editor script that will set the order In layer regarding the z position of the objects for your levels assest ans only change the orderinlayer at runtime for the moving objects.

i’v done it in my game it and didn’t see any problem on performance