Help with 2D Sprite

I need help with something… I’ve had this idea for a while now, but I don’t know how to do it, so any help would be nice.


The idea was for my player, who is set of a 2d sprite, would be able to walk under a roof, and not collide with it, also not going through it though.


I’ll try to explain it in simpler terms…
I want my character to be able to walk under a roof sprite, and whenever the character walks below it, it hides the character, basically in a way that, the character doesn’t go through the sprite, or collide with it, but whenever it goes under it, it will hide the character…


I tried my best to word it…

You could attach an empty gameobject to your roof and add a box collider to it. Make the collider a trigger so the player can walk through it and expand the collider to cover the area you want the player to be hidden in. Whenever the player hits the collider, call your hide function.