• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 Problem with enemy spawning (Tower Defense)

Nawojo

Member
Hi! few days ago i started learning making games with game maker studio 2 and now i have problem,
after a 20 waves (with spawn_rate -=2.5; ) the enemies spawning too thickly. (image) (with another spawn_rate also they spawning too thickly but in another wave, for exaple in 50/60 wave)
after 24 wave (with spawn_rate -=2.5; ) enemies don't appear at all.
Can someone help me with fix this problem?

Spawn object:

Code:
 Create:

     spawn_amount = 5;
    spawn_count = 0;
    spawn_rate = 1 * room_speed; 
     
    alarm[0] = 1;
    alarm[1] = room_speed * 5;
     
    global.hp = 100;
    global.spd = 1;
    global.level = 1; 
    global.coins = 400;

Alarm0:

 if(spawn_count < spawn_amount) && !place_meeting(x,y,o_Enemy) 
     
        {
           
            instance_create_depth(x,y,-1,o_Enemy);
            spawn_count++;
            alarm[0] = spawn_rate;
           
        }

Alarm1:

 if(instance_number(o_Enemy) <= 0)
     
        {
       
           spawn_count = 0;
           spawn_amount++;
           global.level++;
           global.hp += 10;
           global.spd += 0.015;
           spawn_rate -= 2.5;
           alarm[0] = spawn_rate;
       
        }
       
        alarm[1] = room_speed * 5;
Enemy Object:

Code:
Create: 

    path_start(path0,global.spd,0,1); 
     
    hp = global.hp;

Step:

if(hp <=0) instance_destroy();
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Don't do a fixed spawn amount like -2.5... Instead use the wave number to change the spawn rate so do something like

Code:
spawn_rate -= spawn_amount - (spawn_count / 10);

You might want to put a clamp in there on the value too, as the issue with the spawns stopping is because you are setting the alarm to less than 1, which effectively stops the alarm from running... So...

Code:
spawn_rate = clamp(spawn_rate - (spawn_amount - (spawn_count / 10)), 1, room_speed);

You can change the 1 to a different value to prevent them spawning too fast, and you can divide by numbers other than 10 to modify the amount that is being subtracted from the spawn speed.
 
Top