Unity TileMap Grid problem with creating a simple fog of war

1.1k views Asked by At

I have a procedurally generated dungeon BSP on a Tilemap Grid. a TileMap collider has been added to it. I planned to do it simply, since my TileMap contain a SpriteRenderer, I add the color 0,0,0 to it like a black fog of war, and if I can't see it well or have already opened it i would repaint them with 0.5,0.5,0.5, and the area around the player would make 1, 1, 1. and that would be cool, BUT I only can get tiles from the map via VectorInt, or via an index and a copy of the array. Can I access each cell, somehow through a collider? To use something like Raycast or Overlap Colliders. any collider or collision tells me about the TileMap map. Or do I still need to create each tile and attach them to a game object or Scriptable object? I'm confused, tell me, I reviewed many tutorials and questions on this issue and got confused

1

There are 1 answers

2
GabRio Blu On

I don't completetely understand, but I'm pretty sure you want to add a tile during runtime? Or you at least want to change the tile so that it's black or has a fog of war?

First off, I found this link: How can i place a tile in a tilemap by script

However, that would be difficult, having to have some kind of array, or possibly 2d array, of all the tiles for when there shouldn't be a fog of war.

My suggestion is using a Sprite Mask , and setting the tilemap(the actual ground) to not interact with the mask, and having a big fog of war sprite, like a big black cloud that might follow the player around so that it doesn't need to be a massive sprite, and set it's sprite interaction to visible outside mask.

Finally, make a sprite mask that follows the player around, and therefore will remove the fog of war around the player.

Another thing is to make a big cloud sprite with a hole in the middle, and have it follow the player around. That way, there's a big fog of war, but there's a hole in the middle so the fog is not around the player.