How to do a topdown editable terrain tilemap

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Sven Lange
:warning: Old Version Published before Godot 3 was released.

I want to achieve a look like this:

terrain

In sake of simplicity, it should be a simple 2D tilemap, where I can add or remove blocks inside the game.
The visual height effect here is based only on the shadows. Is there an easy way, to compute those? Maybe with shaders? Sadly, I’m absolutely unfamiliar with shaders :confused:

:bust_in_silhouette: Reply From: kubecz3k

As far as I understand you are asking two questions, on how to edit tilemap in runtime and second about lights and shadows.
Runtime Tilemap edition:
When it comes to tilemap edition there is simple function called set_cell(int x, int y, int tile) in Tilemap node. You need to provide x/y coordinates of the tile you want to replace and new tile id. You can extract tile id from the scene from which you generated the tileset - it’s the order of given tile in this scene. Additionally if you push 0 then you will have empty space.
Dynamic Shadows:
If you are looking for dynamic lights and shadows then I can’t really help, but I would suggest to take a look at official demos projects, there is “Isometric 2D + Lighting” demo in which there are dynamic lights in pair with Tilemap.
Shadows with tiles:
If the shadows should be simpler and tile based then I achieved this kind of shadows with tilemap in the past. Basically you need to add second tilemap to the world that will hold shadow tiles (and renders on top of normal one). You need to compute what shadow tile should be in given place based on the local neighborhood (what neighborhood is on the north/south/east/west for given tile - you just take into account if given neighbor is able to cast shadow or not).

Thanks for that hint, but the recommended demo isn’t really helpful in this case.
To clarify my question, it’s not about how to edit it at runtime (think, I can figure that out), but just about that shadows. I just remarked it, because it may be important, that the effect should be able to be done dynamically.

Sven Lange | 2016-03-02 09:42

Well not sure if this will satisfy you, but I made these kind of shadows with tilemap in the past. Basically you need to add second tilemap to the world that will hold shadow tiles (and renders on top of normal one). You need to compute what shadow tile should be in given place based on the local neighborhood (what neighborhood is on the north/south/east/west for given tile - you just take into account if given neighbor is able to cast shadow or not).

kubecz3k | 2016-03-02 09:59

Sounds not too bad and like a doable solution :slight_smile:

Sven Lange | 2016-03-02 10:24

I modified original answer to contain this hint (for other people that will look for that kind of solution).

kubecz3k | 2016-03-02 10:29