How can I check if a position is illuminated by a Light2D node?

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

I know this will sound a bit silly, but I am trying to use a light to accurately find what positions will be affected by an explosion. If possible, i would also like to know how to find the level of illumination.

If it helps, I am using version 3.1.1

:bust_in_silhouette: Reply From: epark009

You can check the distance between your Light2D and each item. Vector2 already has a built in distance_to function. Then you do something like light.texture.get_size() * light.texture_scale and see if the distance is less than that. As for level of illumination, I guess you’ll have to scale it by how far something is from the center of the light.

Just thought of this one. Alternatively, you can add a CollisionShape2D as a sibling of the Light2D, and both a child of some collision body, and let that find out if anything is inside. The thing creating the explosion and the things affected by the explosion would have to be some kind of collision body for this to work.