|Topic was automatically imported from the old Question2Answer platform.
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.
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.
whiteshampoo | 2020-05-16 12:25
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
artsyWraith7 | 2020-05-16 14:51
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)
whiteshampoo | 2020-05-25 11:44
No worries, thanks for the answer that’s exactly what I’ve done
artsyWraith7 | 2020-05-25 12:29