Path enemy not adding to score

I got a little too fancy by creating enemy2 and using the additional enemy image, and everything works, but the adding to the score.

Enemy2 Script:

extends Area2D

signal died

func die():
	queue_free()
	emit_signal("died")

func _on_body_entered(body):
	body.take_damage()
	die()

Game Script:

func _on_enemy_died():
	enemy_hit_sound.play()
	score += 100
	hud.set_score_label(score)

func _on_enemy_spawner_path_enemy_spawned(path_enemy_instance):
	path_enemy_instance.connect("died", _on_enemy_died)
	add_child(path_enemy_instance)

Path_Enemy Script

extends Path2D

@onready var pathfollow = $PathFollow2D
@onready var enemy = $PathFollow2D/Enemy2

func _ready():
	pathfollow.set_progress_ratio(1)

func _process(delta):
	pathfollow.progress_ratio -= 0.25 * delta
	if pathfollow.progress_ratio<=0:
		queue_free()

Any help is appreciate as I’m stuck on this one.

I think I see what’s happening here. I might have even run into exactly this problem when I did this project!

When you spawn a path enemy currently, you are trying to connect path enemy’s died signal to on_enemy_died, but it doesn’t belong to the path enemy; it belongs to Enemy2. I checked this on my own project, and I did indeed have to access instance.enemy to connect the signal:

path_enemy_instance.enemy.died.connect(_on_enemy_died)

Give that a try and let’s see if that fixes it =)

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms