In the example games, it shows a simple way of having the player (top-down or isometric view) to be in front of a low part of an obstacle and then partially behind it, when that positioning is required. It works ok, but only kicks in when the collision boxes touch making it look goofy when you come straight up from the bottom, lot’s of clipping.
I have tried a few things, and they all work only slightly better or require alot of scripting. The only idea I had that works, is to make points on every enviroment sprite where the base of the object is and only compare to that instead of the entire sprite. Is it possible to have multiple collision masks? One could be for collision(of course), and one for a switch. Maybe an invisible sprite placed on the object for switching the z-order?
Does anyone know of an easier way to do this? I am accustomed to using a few other engines and this automatic Z-Ordering is already done for me.
You can always use invisible objects as extra collision masks.
I don’t know if it any better or easier way to do I don’t have much experience either but what I did in my game I was virtually divide the whole map in to zones from top to bottom and each zone had a specific Z order value and simply change the Z order of objects based on their positions on the Y axis.
So let say if an object position on Y axis is >0 and <= 100 I set the Z order to 0 and if it >100 and <=200 I set the Z order to 2
Now for the player I do the same but with different Z order values. If the position on the Y axis is >0 and <=100 I set the Z order to 1 so it is going to be in front anything in the same zone and behind anything in the next zone and just continue the same logic and keep increasing the Z order down to the bottom of the map. So in case the Y position is >100 and <= 200 I set the Z order to 3 so anything in the same zone is again behind the player and anything in the next zone is in front. Obviously you need to take in to account the height of the player and other sprite when calculating the height of the zones. Always best to use tiled sprites with the same width and height like 32x32 64x64 and so on… And to make the impression of walking behind and in front of things when walk up and down to it, you need to make the objects like the tree from two or even more pieces top and bottom and check collision with the bottom part so when the player walk down from the top it stops when colliding with the bottom and remain behind the object and if it walk up from the bottom, again colliding with the bottom part so it remain in front of the object and by changing the size of the collision mask you can allow the player to overlap the bottom part a little so it makes the impression of waking in front but never allow too much space to walk up as it may just change the zone and the player suddenly get behind the tree. It is something you need to figure out for your self to fit your game.
So instead of changing Z order on collision I recommend to change the Z order based on position as I explained above and recommend using tiled sprites or with a tile system in mind so each sprite fit a specific sized tile as it make it easier to design an isometric level.
Ok, thank you for the quick reply. I will try both ideas and see which I like better. Also thanks for being very thorough in your explanation.