+1 vote

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?

in Engine by (13 points)

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.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.