Make a Sprite2D "disappear" in parts as it passes through a specific area

Godot Version

v4.4.1.stable.mono.official [49a5bc7b6]

Question

I haven’t been able to find an elegant solution to this other than animating it all frame by frame.

What I’m trying to achieve is an effect where, as a Sprite2D passes through / behind a specific area, it gradually disappears, as if that node is obstructing it, BUT the node that is obstructing it should be completely invisible. If I move the Sprite2D half way inside it, it should look like the original Sprite2D was cut in half for example.

I want to achieve an effect of an item sinking into the ground when it’s dropped, but this item is dynamic, it can be dropped anywhere, so I can’t use the ground’s Sprite2D for this at all, that’s why the obstructing node needs to be invisible.

Thank you for any ideas in advance!

Hi!

Have you explored clipping?
I’m not sure it fits your use case perfectly, as clipping allows to show child objects as long as they’re inside the parent, so it may not suit your tree structure perfectly, but it’s worth having a quick look at it, I guess?

clip

Another way you could do that is by writing a custom shader for the sprite. Never done that in Godot, but clipping based on a ground level should be fairly easy (as long as it’s perfectly horizontal), although it could be a too complex solution based on what exactly you’re trying to do, visually speaking.

1 Like

That took a bit of fiddling around with but it works as I expected it to! Thank you!

1 Like