Answer the question
In order to leave comments, you need to log in
How to make the player hide behind an object in a 2d game on Unity?
I'm making a 2d game on Unity and I got this problem - I have a character and for example a tree, when I'm in front of the tree, the player's sprite is "on the tree", but when I go behind it, the player's sprite is again "on the tree".
What can be done to fix this?
I will be glad to help!
Answer the question
In order to leave comments, you need to log in
An interesting task, I haven’t solved this myself yet, but I can advise you to add a collider to the tree, check the OnTrigger checkbox and check the Y-axis of the player in the OnTriggerStay2D method to know who is higher, and then just change the Depth of the tree
you need to put a trigger on the tree, a collider on the character. When the character touches the trigger, then move it (the character) along the z axis back.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question