I’m working on a 2d top down game that takes place in the dark. I want to only be able to see what is illuminated by the players flashlight or other sources of light, what is the best way to do this?
1 Answer
1This gives a rough outline of how to set up some way of doing it. In short, it uses raycasting or some other method of knowing the environment (e.g. a path finding grid), and then scans (for the visibility) back towards or out from light sources or other objects that should provide sight.
How this is handled largely depends on how you’ve implemented your game.
From here, it would be something along the lines of handling some sort of mask and adding or removing stuff as needed.
In a 3D game, the lighting itself could be handled by light sources, and a 2D game could attempt to fake this but I couldn’t personally recommend it as I haven’t tried that properly before. In any case, proper line of sight calculation could provide more useful information that puts computers more in line with players, and this is mostly an aesthetic solution.
There’s more thorough explanation of line of sight handling here, and even some sample implementations:
http://www.redblobgames.com/articles/visibility/
I hope this can help you get started.
how could I handle new data to be sent to other players when a player has played his turn? I want to use it also for a chat system inside the game
– skoff
When you say 2D, do you mean 2D playing field in a 3D world (e.g. something like HELLDIVERS or Magicka), or do you mean truly top-down 2D (like Monaco, or something elsee where the camera is perpendicular to and pointing into the playing field)?
– MasterLGHave you tried https://www.assetstore.unity3d.com/en/#!/content/24083 ?
– tanoshimi