Laer Defender: Path enemies won't spawn even though I did everything right

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()

Hi BeanieBoo, and welcome to the community :wave:

out of curiosity, in the EnemySpawner scene, the PathEnemyTimer, has it been set to autostart?

Hello!

Yes both timers are set to autostart.

If you want, zip up your project to folder and pop it o line somewhere and I can have a look at it.

Just thought, the path progress, is it the other way around by any chance?
Like if you see in the scene is 1 at the top right before it enters screen.

But sending me the project would be good, get you back on track a bit quicker hopefully :slight_smile:

Yes it does show 1 at the top right, but when I play that scene the ship goes down normally, but doesnt appear at all during the game scene.

image

Is it possible to send you the project through Gmail?

Yup or Google drive or something.
I’ll pm my email addy

1 Like

hi,

Got the project, thank you .

ive had a look at it, and thankfully its nothing major.

you must have lost the signal connection at some point, since the function is there, and must have been added at some point.

but going back to main game scene, highlight the enemy spawner and on the signals tab in the inspector, you have to reconnect the ‘Path Enemy Spawned’ signal back to the main game.gd script.
the methods there already, so wont overwrite anything.

ive popped a couple of screenshots, just to show what i done.

hope that helps get you back on track.

Darren

1 Like

Hello,

The method worked! Thank you so much!

No way would I have noticed it on my own :rofl:

1 Like

no worries

you would have spotted it, sometimes just takes a break or another pair of eyes to help out :wink:

glad its working and you can keep going :+1:

1 Like

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

Privacy & Terms