Area2D collision signaling instantly at main scene startup

Godot Version

4.6.2 stable

Question

Hey folks, I’m very new to Godot and programming but have encountered an issue/ bug that I couldn’t find a solid answer to. I’m making a flappy bird clone. I’m looking for an answer to why the software does this, not so much as a fix (although that would also be nice).

The issue: I have my main scene set as so:

extends Node2D

var score

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	new_game()

func new_game():
	score = 0 
	$Control/Popup.hide()

func game_over():
	$Control/Score/ScoreTimer.stop()
	$Control/GameOver.visible = true
	$Control/Popup.show()

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
	$Control/Score.text = str(score)

# For resetting the game
func _on_button_pressed() -> void:
	print("button pressed")
	$Control/GameOver.visible = false
	
	get_tree().reload_current_scene()

func _on_score_timer_timeout() -> void:
	score += 1 

func _on_hurdle_game_over() -> void:
		game_over()

and a separate .tscn called Wall that is an incredibly simple Area2D node with a sprite and collisionn2D.

When I start up my game in both F5 and F6 mode it returns ‘wall entered’ immediately. Even though I’ve taken care to keep the collision2D in Wall scaled properly and zero-ed.

It’s an issue because, as per Flappy Bird, the moment you contact a collider the game stops, resets, and you play again. I’ve remade this issue twice now so something is up. I’ll most likely restart the game since it’s so small scale but want to have reference to this issue. I’m curious why this is and how to fix it! There was a post that kinda had the same problem from 2024 but the fix worked around this issue entirely, hoping that this is such a small game this can provide a clear view of the issue.

Thank you for your time.

-Themesong

Can we see the collision layers and masks of the Wall?

My guess is your character2D and wall are instantiated at the same place, then they are moved, maybe you move the character2D in the code at _ready function or something.

Can you share your character2D script also?

My guess is your Area2D case node of your Wall scene has a transformation on it, and is not set to (0,0), so that when you start your game it is moving even though you never see it.

Your area is colliding with the Ground, it is below the world boundry shape.

This isn’t a bug, if you only want the area to detect the player you can assign collision layer/masks or check what the wall hit in code

func _on_body_entered(body: Node2D) -> void:
    if body is CharacterBody2D:
        print("Hit a character specifically")
    elif body is Player: # assuming you have defined a class_name Player
        print("Hit a player specifically")
    else:
        print("Hit something else: ", body)

I think we have a winner!!! :clap: Moving my Wall collision2D above the Worldboundry Shape2D did the trick it seems, so I’ve removed that element and will build around this feature, thank you! For those others who were looking for my Character Script it is the default minus the part keeping the player from infinitely jumping.

Thank you for the input everyone! And thank you Gertkeno for your answer and script, very clever! I’ve learned a thing or two just from your comment alone.