For some reason, enemies that follow the path do not spawn even though I typed the exact code shown in the video. I’m not sure what the problem is as everything looks fine.
Game scene:
extends Node2D
var lives = 3
var score = 0
@onready var player = $Player
@onready var hud =$UI/HUD
@onready var ui = $UI
@onready var enemy_hit = $EnemyHit
@onready var player_hit = $PlayerHit
var gos_scene = preload("res://Scenes/game_over_screen.tscn")
func _ready():
hud.set_score_label(score)
hud.set_lives(lives)
func _on_death_zone_area_entered(area):
score -= 50
area.queue_free()
func _on_player_took_dmg():
#takes away a life
lives -= 1
player_hit.play()
score -= 150
hud.set_lives(lives)
if lives == 0:
player.die()
await get_tree().create_timer(1.5).timeout
var gos = gos_scene.instantiate()
gos.set_score(score)
ui.add_child(gos)
func _on_enemy_spawner_enemy_spawned(enemy_instance):
enemy_instance.connect("died", _on_enemy_died)
add_child(enemy_instance)
func _on_enemy_died():
score += 100
hud.set_score_label(score)
enemy_hit.play()
func _on_enemy_spawner_path_enemy_spawned(path_enemy_instance):
add_child(path_enemy_instance)
path_enemy_instance.enemy.connect("died", _on_enemy_died)
Path Enemy scene
extends Path2D
@onready var pathfollow = $PathFollow2D
@onready var enemy = $PathFollow2D/Enemy
func _ready():
pathfollow.set_progress_ratio(1)
func _process(delta):
pathfollow.progress_ratio -= 0.25 * delta
if pathfollow.progress_ratio<=0:
queue_free()