How to gradually uncover the world once player has "seen" it

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rollup_card

I want to the world to be darkened but visible (but no enemies visible etc) until the player enters the area or their line of sight uncovers it. I want the discovered area to remain light and fully visible after the player looks away. Any ideas on how to do this? I’m not even sure what the effect is called but it is in many games

:bust_in_silhouette: Reply From: Lopy

This is called Fog of War.

You could do this with multiple “fog nodes”. Each would have an area, to know what to hide, as well as a second one to detect the player. Once the player lifts that fog, you show what was hidden and queue_delete the fog.

To hide/darken nodes, you can use the visible and modulate properties inheited from CanvasItem.

:bust_in_silhouette: Reply From: KohuGaly

You’re talking about a fog of war. You can do it by overlaying a tilemap (let’s call it FoW) over the entire map. The tiles of the tilemap are either transparent (for the “visible” areas) or semi-transparent dark (for the “unexplored” area). You can use autotile with smooth transition between the two and/or shaders.
As for hiding enemies, you can add code to them that controls their transparency (color modulation). They check FoW tilemap whether they should be visible or not and set their transparency accordingly. You can add smoothing so they don’t just blink into existence once they enter the view.

There are many possibilities…