Checking whether an object is in shadow or not

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By NiceMicro

Question
Is there a way in Godot to check whether a certain node or is under shadow or is reached by the light of a light source? I.e, if the leg of the enemy is in shadow, I’d like to hide the whole enemy from view.

Context
I’m working on an isometric game. The viewing angle is such that the player might be hidden behind horizontal walls. I use light occluders placed at the TOP of the walls, and the light sources that are used to illuminate part of the map and mask enemies and objects outside viewing range are put at the head of the player.
I decided to add a little script that, upon entering a room, removes the bottom wall and also moves the light occluder from the top of the wall to the bottom, so once inside the room, the player sees everything.
The problem is, that once the player is in the room, enemies that would be in the room BELOW the current room, might have their head peek over the now-lowered light occluders.

What have I tried
I tried to use raycasting between the player and the enemy, so maybe I can find whether there is a light occluder between the origin of the two nodes, but I got super confused by the workings of the raycast, and found no reference whether it is possible to find intersecting light occluder polygons. It got caught however in the different children nodes (collision shapes) of the enemy or the player, even when I’m adding both of them in the exclude array. Admittedly, I’ll have a hard time figuring out raycasting, so I’d like to know if it is even possible to do what I’m trying to achieve here.