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

asked May 15 in Engine by artsyWraith7 (24 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 How to use this Q&A? before posting your first questions.