hello I have an enemy beet that creates bullets using a timer but whenever there is multiple instances of the enemy the bullet timer is out of sync for some of the enemies. each enemy is supposed to shoot 3 bullets at a time but some only shoot 2 bullets instead?
enemy spawn event
If you have multiple enemies, you’re going to have to check multiple timers.
Try wrapping the logic in a FOR EACH (enemy) before you check the timer
I tried for each beet before the beet timer but that didn’t work.
Hey guys, I wanna help you but I can’t even understand how this code shoots three bullets. Isn’t the code supposed to reset timer after shooting each bullet so that it can shoot again?
I think you have some fundamental issues with that logic. From what I understand, you want each enemy (beet) to fire 3 projectiles with an offset of 28 pixels. Something like the below?
I think a simple solution would be to use just a single scene timer, the repeat function and store the offsets in a scene variable.
- The scene variable beets_fire_bullets could be anything really, a boolean, if the enemy is on screen, if they’re X distance from the player.
- The fire_bullet timer is the cooldown between each time the enemy can fire.
- We initialize the _bullet_offset of the variable before we run the repeat action, otherwise the second, third, etc loop would start at the last offset not 0.
- We use the repeat function as we want all the bullets to come out at once. At the end of the repeat function we need to add to the Y offset for the bullets creation.
- Finally reset the timer outside the repeat, otherwise we would call that timer reset 3 times.
Edit: When initlizing the _bullet_offset, it would be better to have it before/above the FOR EACH loop as we’re initializing it for each enemy when we really only need to do it once. Slight oversight on my side
thanks for making an example I did your solution and it works but how do I have each beet fire every 2 sec when the beet is created so they fire at different intervals not all at once?
NOTE I figured out why my events are not working because the beet spawn timer was less than beet bullet timer reset
You’re going to need to use object timers and not a scene timer. That way each object runs on it’s own timer and can shoot independently.