if enemy exited my screen i want the player to die

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By killergaming507

i’m working on a small game and i want the player to die if an enemy exited the screen.
can anybody help me please?
thanks :slight_smile:

:bust_in_silhouette: Reply From: kidscancode

You haven’t provided much information about how you have things set up, so I can only give you general advice.

One way to tell when an enemy leaves the screen is to use a VisibilityNotifier2D (or the 3D equivalent). This node has a screen_exited signal you can connect to let you know when the enemy exits the screen.

You could also do it by checking the enemy’s position property (again, in 2D) and checking if it is outside the bounds of the screen. You can find the screen size using get_viewport_rect().