simulating perspective race game

I have an endless runner through the city in 2d.

I’m programmatically adding buildings at the horizon and they all have the same sort order. but sometimes a building will appear in front of each other. I am scaling them and sliding them slightly left as they come closer.

Should I be looping through a sort order each time I create a far away building or is there a better way.

I’m using 2d characters for the sprites.

What is the best approach to keep the side building scroll like 3d, since eventually I will run out of building sort orders at 32k. Or should I use a z-index?

Thanks,
Nick

you can transpose the items Y position value to it’s layer sort index. (common technique in isometric or topdown games, if you want to look up reference code)

1 Like

Thanks! Works beatutifully.

@enhawk you wouldn’t know if a good link for more info about isometric, so I can absorb some knowedge?

Unity actually has a custom axis sort setting out of the box https://docs.unity3d.com/Manual/Tilemap-Isometric-CreateIso.html

For a simple script to do the same for other transforms, https://assetstore.unity.com/packages/templates/tutorials/isometric-sprite-sorting-125445

1 Like