0 votes

I'm developing a game that has a mechanic where the user uses always a flashlight on dark environments, but when it enters a room with light I want to deactivate the flashlight.

Since the Light2D doesn't have collisions or a body_enter() signal, how can I achieve this?

asked Apr 3 in Engine by Oscar Carballal (15 points)

1 Answer

0 votes
Best answer

You can add an Area2D as child of the light with a collision shape of proper dimensions, so you will be able to tell if you entered in a lit area.

If you use scenes that are either all lit or not, another way is to just check if there is any light in the scene. That can be achieved by either traversing the scene tree, or by putting your light in a group and check if that group has any light.

answered Apr 3 by Zylann (27,004 points)
selected Apr 3 by Oscar Carballal
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.