Godot Version
4.3
Question
I am making a flappy bird clone and I have run into an error I’m not sure how to fix. The error appears when a pipe is spawned in the game. The game works fine but the error makes me think that there is a better way to do what I am doing.
Error:
pipe.gd:6 @ _ready(): Node not found: “bird” (relative to “/root/world/pipe_spawner/@CharacterBody2D@3”).
Pipe code:
extends CharacterBody2D
@onready var score_detection := $score
@onready var top_collider := $"top/top collider"
@onready var bottom_collider := $"bottom/bottom collider"
@onready var player := $bird
const movespeed = -25
func _ready() -> void:
print("pipe spawned")
position.x = 140
position.y = randi_range(40, -40)
func _process(_delta: float) -> void:
if(!Global.paused):
if(position.x <= -140):
queue_free()
print("pipe deleted")
velocity.x = movespeed * Global.difficulty
move_and_slide()
func score_collider_entered(body: Node2D) -> void:
if(body.name == "bird"):
Global.add_score(1)
func player_detection(body: Node2D) -> void:
if(body.name == "bird"):
body.death()
Pipe spawner code:
extends Node2D
@onready var timer := $Timer
var pipe = preload("res://scenes/pipe.tscn")
func _ready() -> void:
timer.wait_time = 5
func spawn_pipe():
if(!Global.paused):
var pipe_instance = pipe.instantiate()
add_child(pipe_instance)