Automatic gradual enemy horde

any ideas on managing an automatic gradual horde of enemies?
I’m currently using this but I have to set the number and name of the enemies to create.


I would like to obtain an infinite gradual automatic creation similar to the vampire survivor video game.
if anyone has already created a game like this and can share I would be grateful

can you explain in basic terms what you want to happen? Like, each wave you want the amount of the previous wave + x enemies to spawn? What is the purpose of the enemy name?

What do you mean by gradual? Gradually increase the rate at which enemies are spawned? Gradually add more monster varieties to be spawned?

If it’s the latter, I’d suggest using an algorithm to determine how many of each enemy to generate.

You could have an array, which would for each wave store the number and ennemy_name to generate.

Which is what @ilary27 is already doing and wants to get away from. Ideally it should be some sort of algorithm or procedural generation.

1 Like

Oups sorry. I misunderstood that sentence. Here is an potential algorithm as mentioned MrMen :
You couldattribute a “dangerosity” to each monster type.
For example :
Skeleton : dangerosity =1
Wolf : dangerosity = 2
Orc : dangerosity = 4

Every new wave increase the “danger level”.
For example, with a formula such as danger level = wave number * 20
Level 1 : danger level = 10
Level 2 : danger Level = 20

Then every new wave you select at random 1 or 2 types of monster and generate of number for wich the sum of their dangerosity matches the danger level.
For example :
Level 1 : Generate 10 skeletons (Total Dangerosity = 10x1 = Danger Level)
Level 2 : Generate 8 skeletons and 6 wolves (Total Dangerosity = 81 + 62 = 20)

To find those numbers “8” and “6” there are different ways. For example you can decide at random at which proportion you first group of monsters will contribute to the total dangerosity (for example pick a random value between 20 to 80%).
In the example above, I had decided that my first group of monsters (the skeletons) would contribute to 40% of the total dangerosity (8 points over 20)

1 Like

yes I mean to build an automatic enemy generation algorithm without having to set it on an array as I’m already doing.
I would like to build a timed survivor game where the player must manage to stay in the game for as long as possible.
I really like your concept, could you kindly build me a small example where I can base myself for the construction of the code

Ok. I’ll see what I can do, to let you start and build on it.
But you should trying building it one step after the other.
You’ll need some variables, to store what your random generator spits out, and don’t be afraid to have many levels of subevents.

1 Like

thanks @vfabien21 your idea of ​​giving a number of danger to the enemy and increasing it every time a new wave starts I really like it. I’m trying to jot something down
I’ll update you

Nice ! I’ll gladly read what you have done and help you if you need !
Doing it myself for you is a bit too much :sweat_smile: : I am trying to move forward on my project.

1 Like

so i added a variable of danger to the enemies and a timer that increases the danger value on the field but i just can’t find a way to make the enemies create in relation to that value.
i attach a small example… kindly if someone can take a look just to make me understand how i can proceed
thanks guys

Hello, here is a quick take at your problem :

I did not use the object variable you created for each object : I don’t know if you can read the variable from an object if there aren’t any in the scene yet.

Also it does not do exactly what you wanted, as i can create any type of enemy whatever the danger level. However, it adaptes their number depending on the enemy’s strength and danger level.

The code (with comments)

The table

1 Like

sorry for the wait in the answer but I was away for the Christmas holidays.
I take this opportunity to wish you all the best and thank @vfabien21 for the time dedicated to create this fantastic example… it was what I was trying to do for a long time.
I only have one last question, in case you want to create waves of different enemies
example:
the danger variable is 15
so it creates (2 enemies5+2 enemies2+1enemy1) or (3 enemies3+1 enemy4+1 enemy2)
is there a way to manage it? thanks again

1 Like

A thing you could do :

Create a local variable to store which proportion you have spent. Make it equal to 0 (dangerProportion)
Make a loop that you repeat 3 times :

  • Pick at random an enemy type ( RandomInRange (0,4) )

  • Decide which proportion of “danger” should be spend on this enemy type, between 10 and 40% (RandomFloatInRange(0.1,0.4))

  • Create the number of enemies corresponding “danger” spent for this enemy

  • Add the proportion of the danger you have spent to dangerProportion

  • For the final iteration instead of picking a number at random between 0.1 and 0.4, take (dangerProportion - 1) (the proportion of “danger” you have spent yet on the 2 previous enemies.

  • Create the last batch of enemies.

Well. I probably haven’t told the whole story there. You’ll have to experiment a bit :wink:

1 Like

I think I messed up… I’m trying over and over again but I don’t think I can fix it on my own.
Please, if you still have a minute of free time to give me, I would be grateful :blush:

Does that code you sent create 3 (single) random enemies ? It looks like what it should do.

Things you could do to get a better understanding of the could I wrote, and yours :

  • What does “Repeat” actually do. And in which order are which actions performed during a frame ?
  • When do the variables change value, and when they are being read ?

When trying to understand I code, it often is useful to take a pen and a paper, and write step by step what the machine is doing in a frame. Also, when I have issues, I use a lot the “Log a message to the console” function to write the values the variables take, and make sure that they do what I want.

1 Like

I know I’m Annoying but no enemies are spawned and the dangerProportion variable drops below 0.

Ahah. You are not annoying. What you are trying to do is complex if you have no experience. I was trying to guide you how to learn.

Can you send your whole project, so I can have a look ?

unfortunately I don’t have a definitive project… they are all drafts.
I have always dreamed of creating a game similar to vampire survivor but until I am able to develop a dynamic of infinite creation of random enemies I will never be able to bring it to life.
at the moment I am proceeding with the creation via array as you can see from the project sent.
what you have developed is actually what I would like but with the difference of creating different enemies in each wave

Well, I have just tried what you have send. Your system works.

What would help you, is that help you debug the code you have commented out ? (The screenshot you have posted a few days ago ?)

1 Like