- Home /
How to make a dynamic fog of war for a 2d maze?
Hey, I'm making a 2d maze game and I have added a mask to make the game a little harder. But the mask lets you look over walls as well. How do I make it so it looks like in the pictures below?
Before: After:
I'm using a tilemap for the maze layout.
The mask is basically a giant rotating sprite that has a hole in the middle.
Of course it has to be dynamic as well.
Much thanks.
Answer by RadonRaph · Nov 25, 2019 at 11:57 AM
Hello @arjenvklaveren, its not build in, And its a little hard to make one, I suggest you to find an asset that do what you want. I've done one for a little project for school that you can see here: https://www.youtube.com/watch?v=qS53HUC4qaE
A little walkthrough of how i made it:
Raycast some rays in the view angle (number of rays depends of the shadow's quality you want)
Save the distance in percent of the max view distance (0-1 scaled)
Create a render texture.
Create a compute shader that compare each pixels to the rays value if its outside the ray range so its black.
Use the render texture as cookie for a light.
This method is for sure not the best one ! But it meeted my needs :) If you wan't the package i can give you :) But an asset from the store will be better i think :)
Hope that will help you,
Raph
Thanks, @RadonRaph, this will definitely help to get an idea on how to proceed. Your game looks great btw.
Your answer
![](https://koobas.hobune.stream/wayback/20220612215257im_/https://answers.unity.com/themes/thub/images/avi.jpg)