Friday, September 30, 2022
HomeGame Developmentunity - Clip a 2D sprite inside a bounding field with out...

unity – Clip a 2D sprite inside a bounding field with out masking


In Unity, engaged on a 2D sport, I’ve a platform sport the place the platforms can “sink” when jumped on. The platforms are 32×32 sprites, and when sinking, the specified impact is to push the sprite down and keep away from drawing the portion of the sprite outdoors the unique 32×32 field:

alt text

I presently do that by putting a sprite masks beneath the platform. It really works very nicely, however the issue begins when I’ve a number of such platforms straight beneath each other:

enter image description here

I can not get this impact utilizing masks because the masks may even partially cowl the higher aspect of the platform beneath. An ad-hoc answer is assigning the sprites to completely different sorting layers, however I generally have many such platforms, and so they’re all conceptually the identical, so I am searching for a cleaner answer.

TL;DR: I wish to outline a “bounding field” for a particular sprite such that elements of the sprite outdoors the field won’t be drawn.

Notice that it is a 2D downside regarding sprites; I’ve seen answer primarily based on 3D parts which aren’t related right here.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments