This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I'm new to Godot and I decided to make a roguelike game to get used to the engine. While I was messing around with light occlusion I wanted the player to be able to hide from enemies when hiding in shadows. I need a way to detect whether the player is mostly in shadow or in light. Is there a way to do this using Light2D and LightOccluder2D nodes?

If not, I could always try ray casting from nearby light sources to check the if the player should be visible or not. I just wanted to know if there was a built-in way to do this.
Thanks :P

in Engine by (28 points)

I don't think so, but you can just raycast2D from enemy -> player. If it hits the player without getting blocked from a wall or something, the enemy can see you.

Good suggestion, but I think I'll raycast from lights, as I want the player to be hidden even if they are stood near an enemy so long as they are in shadow. Thanks for the answer :P

You could also cast rays from the light sources. If any lightsource hits the player AND the player is near enough AND the ray from the enemy can reach the player, then you are detected. (sorry for the late answer, i was busy with a gamejam :x)

No worries, thanks for the answer that's exactly what I've done :D

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 [email protected] with your username.