• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

I'm having trouble getting the enemy to shoot the player

L

likeaboss11123

Guest
I have a script set up so the enemies follow the player when they get close enough I can't figure out a code I can setup in the follow script to make the enemy fire at the player without them spraying just a line of bullets while the player is close
 

Perseus

Not Medusa
Forum Staff
Moderator
An easy way would be to use a "cooldown" timer, so that a new bullet instance is created only after a specified number of steps have passed since the last instance was created.

Code:
if (timer > 0) {
   timer -= 1;
}
else {
   if (point_distance(x, y, obj_player.x, obj_player.y) <= 100) {
      // Create a bullet instance
     timer = 30; // Allow creation of a new instance after 30 steps
   }
}
 
L

likeaboss11123

Guest
An easy way would be to use a "cooldown" timer, so that a new bullet instance is created only after a specified number of steps have passed since the last instance was created.

Code:
if (timer > 0) {
   timer -= 1;
}
else {
   if (point_distance(x, y, obj_player.x, obj_player.y) <= 100) {
      // Create a bullet instance
     timer = 30; // Allow creation of a new instance after 30 steps
   }
}
Thank you I'll try this
 
Top