1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GMS 2 Problem with enemy spawning (Tower Defense)

Discussion in 'Programming' started by Nawojo, Feb 12, 2020.

  1. Nawojo

    Nawojo Member

    Joined:
    Feb 12, 2020
    Posts:
    3
    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(); 
    
    
    
    
    
    


    [​IMG]
     
  2. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    7,144
    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.
     

Share This Page