How do I spawn enemies

hi, I have 3 types of enemies in my game.
I want that when the scene starts, two “Enemy1” spawn.
When they get killed (i already know how to kill them) it appear “SECOND WAVE” and then, after a few seconds, will spawn one “Enemy2” and one "Enemy3 ".
Also, I want that the enemies spawn randomly at the borders of the screen.
How do I do that?

What are you having trouble with?
To spawn enemies, use the create object action.

I tried but with it, or it spawn only one in a precise point of the border that I define or will spawn infinite enemies in a random point of the screen. I want that spawn only one enemy and in a random point in the border…

Infinite spawns means you miss a ‘trigger once’.
Precise point means you don’t use random :man_shrugging:

Just some thoughts that may or may not help you:

If you want them to spawn after a few seconds, I assume you’ll use a timer. Have the condition be when the timer reaches a few seconds, and the action be the spawning. If you also include an action that pauses/resets the timer, I think that will help with only spawning one enemy since the condition will only be true for one frame.

There are functions with “screen width” and “window width” and also “camera x” and “camera y”. These might be able to help you with a spawning location along the border that works no matter where in the scene your player is.

There is also a “random in range” function that might help you with spawning at random spots along the border.

That’s probably how I’d start going about achieving what you described. Hopefully this can help get you going.

1 Like


I did this but every 5 seconds spawn infinite enemies again.
If i delete the timer instead of pauseing it, spawn a new enemy every 5 seconds.
How do i spawn for example 2 “Enemy1” after 5 seconds and then, when killed, spawn a “Enemy2”. After 5 seconds spawn a different one, after 5 five seconds spawn a different one,…, for infinite times?

Add a second Create object action.
Add “trigger once” condition!
Don’t delete the timer, otherwise he will always triggered.
Pause all timers you want to use later at the beginning of the scene, otherwise they will always triggered.
Add a variable with the default value 2. Subtract 1 when killing the first two enemys. if the variable is 0, you can unpause a new timer for the other enemys.

1 Like

If you pause the timer, the value of the timer is still greater than 5 seconds, so it keeps creating objects. You need to pause AND reset the timer.

Another way to proceed:
Group all your enemies objects together, call the group Enemies.
Spawn Enemy0. Increase variable WhatToSpawn by 1.
If number of Enemies = 0 (player has killed the available enemy), reset timer WhenToSpawn.
If WhenToSpawn > 5 and number of enemies = 0 (no enemy has been added)

  • if var WhatToSpawn = 1 , create enemy1, Increase variable WhatToSpawn by 1.
  • if var WhatToSpawn = 2 , create enemy2, Increase variable WhatToSpawn by 1.
  • etc
1 Like


so… I did this. I don’t really know if is what you thought before.
Anyway, it spawn the first enemy (Enemy1) and it stops everything spawning nothing.
I think the probelm is the timer but I am not sure…
What i did wrong?
P.S. Sorry I’m new in gdevelop and I’m learning

Why do you do the actions separately? You should make the same enemy creation action reset the timer and voila, you don’t need to do it separately. As for what to make the enemies appear on the edges, at least I don’t know an immediate solution but a good one … you could create 4 different objects as stripes, one on each side of the edge, and then on each one throw edit points on each edge.
Then when you create the enemy, you set an object variable “Enemy” in the same create action (to apply to the created object) randomly in the whole number range from 1 to 4. Finally, for each object variable, You must set the enemy position to be changed in each strip (for example, variable 1 for the right strip, variable 2 for the upper strip, 3 for the left strip, and 4 for the lower strip) in the random range between each of the points on the edges of those stripes, respectively.

I separeted the actions because i want to decide what type of enemy i will find when the game start:

-Game start
*5 seconds
-spawn one Enemy1
*when killed -> 5 seconds
-spawn one Enemy2
*when killed -> 5 seconds
-spawn two Enemy3
*when killed -> 5 seconds
-spawn one Enemy1 and two Enemy2
*when killed -> 5 seconds

And doing it for lot of times.
So I can decide what type of enemy you will find and how many of them.
How can I do it?
Sorry if i didn’t explain clearly before.

You can also combine all enemies into one object and only change the animation image.

2 Likes

Thank you so much. Tomorrow I’ll try it :grinning:

How do I do "If one of these condition is true: "?

That is the “Or” condition.

Alternatively replace it with this

i did but it doesen’t work. It spawn the first enemy (Enemy1) and then nothing appens



Thi is my whole code…

“Enemies” is a group with all enemies?
I think that doesn’t work, the correct enemy doesn’t get dmg/dead.

Yes, all 3 enemies are in a group called “Enemies”. How do I fix it?
In the code that you send before, I didn’t use the group. I used the enemies one by one

Okay idk about groups maybe Gruk can help.
I did my spawn part and it works✌️
But one point will be that you cannot check if an enemy is dead unless you delete them first.