Having trouble with Area2d nodes not working

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

I’m trying to make a platformer about a snake running around and making difficult jumps and if you fail them you die. I tried using a single Area2D node for the ground so that if you fall you die and change scene this is the code:

func _on_Area2D_body_entered(body):
get_tree().change_scene(“res://Death Screen.tscn”)

it’s connected through an on_body_entered Signal.
I tried putting 2 of them in a single scene but it automatically changes to the death screen even when the player is not touching any of the 2. Can someone help me?

:bust_in_silhouette: Reply From: yrtv
func onArea2Dbodyentered(body):

Is called then any PhysicsBody2D enters Area2d

So it goes like this.

  1. Your platforms are StaticBody2D
  2. One of them barely touches Area2D
  3. Death screen

Use Collision layers and masks or check body parameter in if statement. (Collision layers is better, with if Area2D still calls function on every collision)