SOLVED enemy shooting cooldown

A

abde

Guest
hi imworking on an ai and i made the enemy shoot but
Capture d’écran 2021-01-28 213506.png
i think u see ,it doesn t stop and i need a cool down here the code
image_2021-01-28_213931.png
here it create the bullet , thougt of making that if the instance exist(i know the function) it will make the
function false can you help me fixing ,thanks
 

rytan451

Member
GML:
// Create
reloadTime = 1 * room_speed; // = 1 second
reloading = 0;

// Step event

// Make the reload timer count down
if (reloading > 0) {
  reloading -= 1;
}

if (/*whatever condition that makes the AI want to shoot*/) {
  if (reloading <= 0) {
    // Set the reload timer
    reloading = reloadTime;
    
    // Create the bullet
    instance_create(x, y, enemyshoot3);
    instance_create(x, y, enmyshoot2);
    instance_create(x, y, enemyshoot3);
  }
}
 
GML:
var inst_1 = instance_create(x, y, enemyshoot3);
inst_1.alarm[0] = your_cooldown*room_speed;
The alarm[0] code in enemyshoot3 will trigger your_cooldown seconds after it's created.
Not too sure I understand your endgame here, are enemyshoot enemies, or bullets? Anyway, you can use alarms for cooldowns no matter what.
 
Top