In Unity, working on a 2D game, I have a platform game where the platforms can "sink" when jumped on. The platforms are 32x32 sprites, and when sinking, the desired effect is to push the sprite down and avoid drawing the portion of the sprite outside the original 32x32 box:
I currently do this by placing a sprite mask below the platform. It works very well, but the problem begins when I have several such platforms directly below one another:
I can't get this effect using mask since the mask will also partially cover the upper side of the platform below. An ad-hoc solution is assigning the sprites to different sorting layers, but I sometimes have many such platforms, and they're all conceptually the same, so I'm looking for a cleaner solution.
TL;DR: I want to define a "bounding box" for a specific sprite such that parts of the sprite outside the box will not be drawn.
Note that this is a 2D problem concerning sprites; I've seen solution based on 3D components which are not relevant here.