Hi,
I'm struggling with this one. In my 2D platformer, I have an enemy that I'd like to spawn a few seconds after the player spawns. I've been trying to do it with a SceneTree timer, but maybe I'm wrong about where to place this in my enemy's code.
Here's the relevant code:
func _ready():
rng.randomize()
position = startpos
start_delay()
$Timer.start()
$AnimatedSprite.play()
func start_delay():
rng.randomize()
var waitstart = rng.randf_range(3.0, 6.25)
print (waitstart)
yield(get_tree().create_timer(waitstart), "timeout")
So I've created a start_delay() function that should pause a random amount of time between 3 and 6.25 seconds, and inserted it into func _ready(). Ignore the $Timer.start() line (it's referring to another timer used later for the enemy's movement).
What's happening is that my enemy is still spawning in at the start of the level with everything else. Is there a way to make this delay happen inside the enemy's code, or will I have to write it into the code for each level?
Thanks in advance for any light you can shed!