What approach for "smooth" 2D terrain that can be dug into / subtracted from

Godot Version

4.7

Question

Context

I have a bit of GDScript knowledge, using the free “Learn GDScript From Zero” course. It’s my first real knowledge in code-based programming, after previously having made simple games using visual programming tools like Scratch/Turbowarp. It was nice to gain fundamental knowledge in programming concepts that was still missing when I was using Turbowarp.

In terms of in-editor experience, I have followed the Dodge The Creeps example from the documentation, and I have managed to built a simple project from scratch that contains functional movement mechanics and platform tiles for a 2D platformer (not a game yet).

The game mechanic idea

The idea for this game I want to make is a 2D sandbox, and involves sitting inside a drilling vehicle, which can drive on the surface, then drill down, explore some of the deep earth, and return to the surface again. This is just one part of the game idea, but the rest is irrelevant.

When the drill of the vehicle collides with the terrain, it should remove that part from the terrain. Ideally this also affects the hitbox of the terrain. I know this is quite a complex game mechanic for my first Godot game, so I’m okay if there are objections to this being part of my first Godot game, and then alternate beginner-friendly learning paths being suggested.

Actual question

What approach to take for freely shaped 2D terrain which can be dug through?

What I have looked into

TileMapLayer (easiest, but I’m not sure if it fits the idea)

As I already have experience with TileMapLayer, to make terrain, I could research how to make individual tiles removable. And I could scale the tiles down, so that it becomes easier for the drilling vehicle to traverse diagonals.

This approach worries me a bit though because from an aesthetic level, I want the driving experience on the surface and in the tunnels to feel smooth, and not like it’s bumping up and down constantly because of blocks underneath it.

TileMapLayer (but super small) ?

I could try going microscopic with the tiles, which is kind of what Noita does:

I would need to research how I will texture this tiny tiled terrain, as currently I don’t know what method to use.

Custom polygonal / 2D mesh approach (hard)

Probably the most complex one. It’s an approach inspired by Big Bang Racing, which does this idea, but with 3D depth. In their game, it’s used to “paint” a terrain as well instead of just removing terrain.

Having this kind of mechanic in 2D would most closely resemble my dream outcome (but it’s ambitious for a beginner like me)
I researched getting custom terrain colliders in 2D, and landed here: 2D meshes — Godot Engine (stable) documentation in English
This tells me I can use a Sprite2D node with a partially transparent image to quickly create a custom collider which matches that image.


This is where I ended up writing this post, because after I learned this, it got me thinking there might not be an accessible way to “subtract” from custom collider shapes (and also the terrain sprite), and might involve coding complexity I am not yet prepared for.

Thoughts?

If you have any thoughts I would love to hear them! Or any resources or examples that can help learn me some more fundamentals for this goal are also welcome.

Marching squares.

I’ve not heard of that. I’ll look into it, thanks for the advice!

Generally these require specialized techniques at a close to engine level, Terraria and Noita are not using Godot or anything close to it, they are built from the ground up to support this kind of simulation. You will not get such functionality out of Godot’s TileMapLayers, or at least not without performance problems.

“Greedy Meshing” is another term that may help, and Godot does (recently) use for reducing TileMapLayer collision complexity. It is usually the first step to optimizing voxel style games where the user can build or destroy blocks at will.

Thankyou, this helps clarify the complexity of this task and the search term that can help me create more optimized TileMapLayer colliders!

With this in mind, I’m considering learning to make a full game idea that mainly relies on TileMapLayer first, and then when this is done I have much more experience in coding, the step to making my marching squares terrain using custom rendering would be less daunting.

Then that would be my 2.0 version of the game.