Godot Version
4
Question
I’m trying to make it so it spawns an enemy that follows a path, but my scene has the mobs as a mob scene in a node2D, and i dont know if that will work with it or if i should just change the mob to a character body and manually add it
extends Node
@export var mob_scene: PackedScene
var score
func _ready():
new_game()
func game_over():
$MobTimer.stop()
func new_game():
$Player.position = $StartPosition.position
$StartTimer.start()
func _on_start_timer_timeout():
print ("timer good")
$MobTimer.start()
func _on_mob_timer_timeout():
print("mob timer triggered")
var mob = mob_scene.instantiate()
print ("mob instantiated and added")
var mob_spawn_location = $MobPath/MobSpawnLocation
mob_spawn_location.progress_ratio = randf()
var direction = mob_spawn_location.rotation + PI / 2
mob.position = mob_spawn_location.position
direction += randf_range(-PI / 4, PI / 4)
mob.rotation = direction
# Spawn the mob by adding it to the Main scene.
add_child(mob)
func _on_hit():
_game_over()
func _game_over():
$ScoreTimer.stop()
$MobTimer.stop()
func _new_game():
$Player.start($StartPosition.position)
$StartTimer.start()