There is a couple ways I can see for doing this, though I have not tried either myself.
The first, easiest, and most likely to work way would be to place Area2D nodes on every light source you have in your game, and then check if the player is within one of these areas. It would not be detecting if the player is in a light source necessarily, but if done correctly it would give the illusion of knowing when the player is in the light or not. I know this should be doable, and with some additional post processing (like using raycasts to detect if the light can actually reach the player) you can use it for line-of-sight for AI entities as well.
The second way is to write a shader and use the Light
function. You could expose a boolean uniform in the shader and set the boolean to true in the Light
function when the sprite it exposed to light and false
when it is not. You could then read the results of the boolean in GDScript and have your code react accordingly. I do not know if this method would actually work, but it might be a way to get a more accurate result of whether the player is in the light or not.
Hopefully this helps, and welcome to the forums! :smile:
(Side note: Please do not create duplicate posts. Thanks!)