|
|
|
 |
Reply From: |
TheNewGrant |
Sounds like you need the timer node for this. With the timer node, you can set its wait time (time waited before returning timeout() signal) to 10 seconds.
Your code could look like this.
Setup: Add Timer node to hierarchy, connect timeout() signal to the script, set wait time to 10, set autostart to true (to start adding enemies as soon as the timer node loads).
Possible code:
func _ready():
$Timer.start() # If autostart isn't selected, will start the timer
spawn_enemies(spawnrate) # Do this or else it will take 10 secs
# before enemies spawn
func _on_Timer_timeout():
increase_spawnrate()
spawn_enemies(spawnrate)
$Timer.start() # Restart the 10 second timer
Don’t forget to make your increase_spawnrate and/or spawn_enemies functions to spawn your monsters.
Go here for some more documentation on Timers.
You already have your increase_spawnrate function set up. From the look of it, it will work fine. For a spawn_enemies function, you can set up a variable (outside the function)
loadEnemy = preload("res://path_to_enemy_scene")
or
loadEnemy = load("res://path_to_enemy_scene")
Either work, the first loads the enemy at the start of the scene, the second loads the enemy when the code is executed.
After that, you will need to add the enemies to the scene (you can do this in a spawn_enemies function)
func spawn_enemies(spawnrate):
for enemy in range(spawnrate):
enemy = loadEnemy.instance()
add_child(enemy)
this function creates a new instance of the enemy scene and then adds that instance to your hierarchy as a node.
Edit: I noticed that you wanted your number of enemies to increase in a linear fashion. By multiplying to your spawn rate you are increasing the number of enemies spawned at a quadratic rate. To make it linear just add a specified amount to your spawn rate (like spawn rate += 2)
Thank you for the long answer! I see you worked hard on this. But I think I might have given too little information. The spawning and the method calling every 10 seconds IS working. I just don’t know how to increrase a number in a SINE wave sytle. Not linearly.
Do you have an answer for that? Sorry, for the hastle I created by being unclear.
TheoTheTorch | 2021-03-28 11:37