How I Created The Fog


Hi! This short Devlog is going to be about the fog of my game jam game "The Keep of TIME" where you play as a human who fell in the keep.

In the game, you reveal  areas around you! Which for now lets call the Fog. It is pretty simple to make all you need to set it up is a black square tile to use in the Unity tilemap that you are going to fill with small black squares! Create a new Tilemap object in your hierarchy, select the grid object that is a parent of the tilemap and change the tile size to something that is small like 0.2 on the x and y:


Then change your black square's pixel per unit until a square occupies only 1 slot in the tilemap. Fill the tilemap with the squares until you are satisfied! Then, lets get to the code!


First, we need to break down what we need to do:

We need to check the player's position and then we will need to create a circle around the player to remove the tiles!


Create a new script, mine is called TileRemover. Attach it to any GameObject (preferably the tilemap object) and lets create our tile remover

The variables that are needed are:


The oldPlayerPos is to not waste performance on creating a circle around the player if he did not move at all.


We will need to check if the player position is the same last frame:


if it is, we will return and will not do anything.


Then we will to get the player's position in the tilemap which is a method returning a Vector3Int I called RoundPlayerPosition()



Then we will need to create a circle around the player which is defined by doing this:



We will then create a Vector3Int of the position in the circle by doing this:




Then check if the position in the tilemap is not null, if it is not null set it to null:



So the whole block of code should look like this:




Then fill the variables in the inspector and you just created the fog effect in my game!

Leave a comment

Log in with itch.io to leave a comment.