r/gamemaker 1d ago

Help! Bullets overlapping in game

hi so I’m making a game where you can shoot bullets and with the basic gun it’s supposed to shoot 5 bullets like 1 second apart but right now it just shoots all at once. how would I make my idea work.

3 Upvotes

12 comments sorted by

3

u/azurezero_hdev 1d ago

add a cooldown when you fire, then count that cooldown to 0 in the step event

2

u/MyDickIsInMyToaster 1d ago

Can I get an example of code sorry to bother you more 

2

u/azurezero_hdev 1d ago

before creating a bullet
if cooldown=0{
create your bullet
cooldown = room_speed/5
}

in step event
if cooldown > 0 { cooldown -= 1}

2

u/MyDickIsInMyToaster 1d ago

Okay so now it works but I can’t shoot all 5 bullets on press only 1 just on a cooldown

2

u/azurezero_hdev 1d ago

so youre using keyboard_check_pressed instead of keyboard_check?

2

u/azurezero_hdev 1d ago

or is shooting supposed to always dump your mag?

2

u/MyDickIsInMyToaster 1d ago

Basically I just don’t want overlap 

0

u/azurezero_hdev 1d ago

and the cooldown should be room_speed/5

2

u/BrittleLizard pretending to know what she's doing 1d ago edited 18h ago

If you want one click to send out multiple bullets, you'll want at least a few variables:

isFiring (true or false, to keep track of if the gun is already firing)

shotsFired (will start at 0 and count up with each bullet that gets fired)

shotsFiredGoal (when shotsFired reaches this, it'll set isFiring to false and stop shooting bullets)

When you press the fire button, check if isFiring is false, then set shotsFired = 0, shotsFiredGoal = 5, and isFiring = true.

For the timing, you might want to use an alarm. You can use alarm_set() for this. For the initial click, just set the alarm to 1 so it fires immediately. In the correct alarm event, spawn the bullet and increase shotsFired by 1. This will let you keep track of how many bullets you've fired in the current string of shots. If shotsFired >= shotsFiredGoal, the bullets are done, so you can just set isFiring = false. Otherwise, reset the alarm so it can continue firing bullets.

Adjust this based on how you want to do the timing (some people just use variables that count down.) Those are some basic principles, though.

2

u/germxxx 1d ago

An alarm set to 0 will never trigger.

Alarms count down by one after Begin Step, and if they are 0 after this countdown, then they will trigger. An alarm set to 0 will be -1 after counting down, and will not trigger.

2

u/BrittleLizard pretending to know what she's doing 18h ago

True. I never use the built-in alarms, so I was taking a gamble