How do I check if the player can see something or not?

Godot Version

Godot v4.1.3

Question

I want some streetlights to turn off when the player isn’t looking at them. Probably has to do with either a Camera3D or a Viewport - if the screen does not contain any trace of this SpotLight3D I’ll queue_free() it. How can I check that?

You can use the VisibleOnScreenNotifier3D node to do that. It’s a bounding box that emits the screen_entered signal when entering the screen and screen_exited when leaving. If you resize the box to the area that the spot light casts, you should have a good approximation.

Only question is… why would you want them to turn off when the player isn’t looking at them anyways? You could just leave them on. This is a “If a tree falls in a forest and no one is around to hear it, does it make a sound?” kinda situation. XD Unless you want them to be off permenantly after looking away, I guess. ^^’

Permanently, yes. To creep them out >:)

1 Like

Okay this works. Shame it only uses boxes though. Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.