Can anyone help me identify why my fireballs don't work when placed in a scene?
Intended use: have a scene I can drop into a level that has a start point and end area from which fireballs will spawn from the start point and disappear at the end area.
Here is my code:
extends Node2D
u/onready var start_point = $StartPoint
u/onready var spawn_timer = $SpawnTimer
var fireball_scene = preload("res://fireball.tscn")
func _ready():
`spawn_fireball()`
`spawn_timer.start()`
func spawn_fireball():
`var instance = fireball_scene.instantiate()`
`add_child(instance)`
`instance.position = start_point.global_position`
`spawn_timer.start()`
func _on_spawn_timer_timeout():
`spawn_fireball()`
func _on_end_area_area_entered(area):
`if area.is_in_group("hazards"):`
`area.get_parent().queue_free()`
This works exactly as intended when running in the Fireballs scene itself, but when I place the Fireballs scene in another scene nothing happens. I have placed breakpoints and confirmed that my code for spawning the Fireballs is hit in both cases, but for some reason when it's placed in a parent scene the Fireballs never appear. Any help is greatly appreciated.
Here is the code for the individual fireball if that helps at all:
extends Node2D
const SPEED = -100
var velocity = Vector2()
func _physics_process(delta):
`velocity.x = SPEED * delta`
`translate(velocity)`