+1 vote

Hi guys I know how to restart the game but I do not know how can I configure an object that triggers the restart. For example in an endless runner like flappy bird are the tubes deadly for the player. How can I make the tubes deadly?

in Engine by (16 points)

Let me see if I understand this correctly. You need a state such that, when the main character is defeated (e.g. "killed"), it then resets the game? If that's correct, your game needs a "game over" trigger (the bird touching the tubes, for instance). In the case of Flappy Birds, the "game over" trigger looks like this:

  1. Move bird according to user's input.
  2. If the bird collides with a pipe (one that may have an Area2D node), go to the "game over" state.
  3. Reset the game from the beginning.

And how can I collide the bird with the object?

1 Answer

+1 vote
Best answer

Assuming you have a 2D flappy bird-type game, you need to place Area2D nodes on both the bird and the tube.

1) Create Area2D nodes for your bird and tube objects

2) Create a new script for the tube.

3) Set up an area_entered signal from the Node tab (next to the Inspector tab when you select an object in the editor). Connect the signal to the node that holds the script.

4) A new _on_Area2D_area_entered(area) function appears in the previously created script. Put your logic here. The gist of it all is that when another Area2D collides with this object, you want to check what this other Area2D is, and if it is the bird, you restart the game. You do it somewhat like this:

func _on_Area2D_area_entered(area):
    if area.name == "Area2D":
        get_tree().change_scene(MainScreen) # change to another scene
by (1,838 points)
selected by
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.
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 webmaster@godotengine.org with your username.