Walking in front of / behind object with conditions

Hello everyone, I would like to do this (red : player, blue : tree trunk to collide with, red, tree trunk collider collision limit, black : tiles) :

6941828--816062--example.png
This is a 2D unity game using tilemaps (Unity version 2019.4.14).
The main goal is for the player to walk in front of the trunk if it comes from below and behind if it comes from above.

Here is what I tried :

I have a Polygon2DCollider on the player and tried to add a small Box2DCollider for this specific use (not necessarily the best idea …).

I can move layers sorting order dynamically in C# and even select the player collider when the collision occurs, but I am not sure how to detect whether the contact points come from above or below.

I generated custom Physics shapes on the tilemap sprite editor to match the tree trunk shape, but can change to a smaller one like the green line on the attached image.

If someone’s got an easier solution I am really up for it.

Thanks a lot for reading :slight_smile:

Try something like this:

Hi, thanks a lot for the video link, it is very useful.
How can I apply a script to individual tiles of my tilemap instead of individual game objects as shown in the video ?

That sounds like a fantastic google question

Using individual sprites instead of tiles was better for me

change tile map renderer mode from chunk to individual

use transparency sorting axis for y or z