Why does going offscreen work but colliding with a tree doesn't work

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

Hello!

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):
print(body)
if "trees" in body.name:
            #call the exact same death function
	death()
	
func _on_VisibilityNotifier2D_screen_exited():
       #call the exact same death function
   death()

 
#death function
func death():
   $death.play()
   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:
	return
if Input.is_action_just_pressed("ui_up"):
	Global.gamestart = false
	Global.score = 0
	get_tree().reload_current_scene()

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

:bust_in_silhouette: Reply From: Wakatta

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
    death()

what are the results of your print statement?