Suggestions for implementing digging like mechanics

game

Hello everyone,

I have two objects, like the red and blue circles in the attached image, and an obstacle like the brown shape. The circles need to move from A to B but only the red circle can destroy the brown material. The blue circle can move only over white background, so it collides with the brown shape and can only follow the path the red circle cuts.

My first idea was to use tilemaps, but I would have to use really small tiles to achieve a smooth margin. This means the number of tiles will increase and I’m thinking this will have a performance penalty.
My second idea was to use masking with a stencil buffer. But that won’t give me collisions for the blue circle.
Next I thought I could combine the two, use invisible tiles big enough to have a reasonable count, but small enough to be able to approximate the shape of the tunnel. And over that, paint the smooth margin as resulting from the stencil buffer mask.

How would you do it? Is there a better/simpler way?

Personally, I’d look into using SDF (Signed Distance Field) textures.
That will allow you to not only “dig” with accuracy , but also give you accurate collisions.

Here’s an old presentation about this:
(Collision starts at page 43)

As our physics engines don’t support sdf’s, you’ll need to implement collision mechanisms yourself.
Since your objects are balls, or at least small and ball-like, it shouldn’t be a huge issue.

1 Like

Thank you Mathias, for your suggestion. I looked over the document and it looks promising. Although the concept seems simple enough, I’ll have to do some more reading both on the subject and how to implement that technique in defold, because at this point it appears I have serious knowledge gaps :). I’ll get back with my progress, or the lack of it :).