Godot Version
4.3
Question
Hello everyone, this is my first post on something like this.
I am trying to make a 2D stealth/ infiltration game and i’d like to find a way for the game to know when the player is in a lighted area or a dark one dynamicly.
i have no idea how to proceed and i know there are ways to do so in 3D.
Please help me ! 
thanks in advance.
I hope this isn’t too late.
the simplest way is to manually find the areas that will always be dark or on light and use Area2D
s, and then detect if the player has entered for enemy detection or to just tell the player.
you can do this for dark areas or light areas or both, that depends on your game. this was done for Arkham Asylum during the scarecrow level.
for dynamic detection, that is up to the enemies, which usually have cones of view. these can be Area2Ds as well, or you can cast rays.
an option is to cast a bunch of rays mostly covering the area that that enemy sees, another would be to have a single ray in the center.
rays will garentee that you can take cover behind crates or pillars.
using areas for cone of view, you can combine them with the dark area2Ds to create “safe” areas where the enemy can’t ever see you. at this point it is a good idea to add some randomness by rolling a dice to see if the enemy has detected the player or not, and the areas would provide “bonuses” to stealth or against it.