Implementing widespread directional light beam

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

I posted this question a couple of days ago on the Godot subreddit, but received no response so I’m hoping that maybe someone here might be able to help me out.
The post went as follows:

I would like to implement in my game an object that behaves like a directional wide beam of light (like a sunbeam for instance), which the player can detect when touching. However the light should not pass through light occluding objects such as platforms or walls, so when the player is standing in the shade of one of these, they are not able to detect the light and the sprite of the light is masked to give the impression of a shadow.

I have played about with an Area2D with a child Light2D, as this object has almost 1:1 behaviours with what I’m going for, but I cannot work out how to make inactive or trim away the areas of the Area2D which end up in a shadowed area so that the player no longer detects the object. I also wondered if it was possible for the player to detect the colour of the object it was interacting with (ie, all of the player is touching sprite value which is less than 0.5,0.5,0.5), but I don’t imagine this is feasible at all.

I’ve considered using the RayCast2D object, but I’m not sure how I would make this work for a light that has a width, like the implementation I’m going for.

Could anybody provide some ideas or suggestions on what I might be able to do to achieve this beam object?

Don’t know whether I can help you, but have you looked into using a shader? I’m thinking of something like a XOR with the light, and the object which is occluding it. Try to detect that with your player node.

Ertain | 2019-03-08 00:24