0 votes


I am a beginner at Godot, and I am currently making a flappy bird clone. The trees are the obstancles and the player is a plane

I made it whenever the player collides with a tree or go offscreen, you would die and restart the game. It detects when it's offscreen by using a visibilitynotifier2d and connecting a screen_exited signal to my script. However, when I collide with a tree, it doesn't let me restart the game even though they call the exact death function.

Here is my current code for the player detecting and killing the player:

func _on_Area2D_body_entered(body):
if "trees" in body.name:
            #call the exact same death function

func _on_VisibilityNotifier2D_screen_exited():
       #call the exact same death function

#death function
func death():
   Global.pause = true
   Global.gamestart = true
   get_parent().get_node("CanvasLayer/restarttext").visible = true
   get_parent().get_node("CanvasLayer/score2").visible = true

func _process(delta):
if Global.gamestart == false:
if Input.is_action_just_pressed("ui_up"):
    Global.gamestart = false
    Global.score = 0

What I am doing wrong, and sorry if this answer is obvious, I'm a complete beginner

Godot version Godot 3.51
in Engine by (12 points)

1 Answer

0 votes

For a newb you're doing pretty good.
It depends on where the following code is called
Assuming it's attached to the trees Area then body should be that of the "bird" node

if "trees" in body.name:
  6  #call the exact same death function

what are the results of your print statement?

by (6,876 points)
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.