0 votes

I am making a game in the style of older Zelda games, like Link's Awakening. I want to have the enemies by inactive when the player is in a different room, and to be reset to default status when they leave and reenter.

I know to use an Area2D to trigger the pause and reset, but I don't know how to code this in.

Or should I just make spawner nodes that spawns the enemies in when the play enters and removes them when they leave?

in Engine by (28 points)

1 Answer

+1 vote

There are many ways to approach this problem, but I would like to promote one sollution I learned about not so long ago, and it seems perfect for your situation:

There is a node called VisibilityNotifier. You can child it to your enemies, and it will emit signal, when they go off screen. You can connect something to this signal to pause them, and unpause when they will be back on screen.

by (7,755 points)

Alright, but how do you pause an individual node? Everything I have read is pausing the entire scene and making some exempt from that.

You have put all this work to code some behavior in enemies, and all it takes to pause is to NOT let that code go :). It can be easily done by tactically placing RETURN in most important functions. So I would create some boolean var "paused" and use it in conditions like these :

func physcics_process()
       if paused == true:
              return
       movementcode
       animationcode
       AIcode
       whatevercode

this first condition stops all the code below it if paused is true

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.