How do you control rate of fire?
Side scrolling ship shooter. How do I limit the fire rate? Right now it as fast as you press the button. How do I set it up so that no matter how fast they press it will only fire 1 a sec, or if I want 1 every 3 seconds etc? It can't be just hold the button down, I need them to press it. Any ideas?
Comments
Timer:
Every x seconds, do the following behaviors:
Spawn actor--bullet
Then make x a global attribute, and you can mess with it however you like. Even change it in game (for instance, you hit a powerup, that doubles your output--you just make x = x * 2.)
Besides a timer setting what else do I need to do?
1. Fire button
2. Player
3. Bullet
Create two global attributes:
1. BulletFireRate (real)
2. Fire (boolean)
-------------------------------------
In Button actor:
Actor receives event: Touch is pressed:
Set fire to true
Otherwise:
Set Fire to false
-------------------------------------
In Player Actor:
When Fire is true
Timer:
Every "BulletFireRate" seconds, do the following behaviors:
Spawn actor--bullet
-------------------------------------
Now, if BulletFireRate is 1, the player will fire bullets every 1 second. If BulletFireRate is .5, it will fire bullets every .5 seconds, or, double the bullets.
If I turn back on the 'otherwise', it won't fire. If I HOLD DOWN the 'button', it will fire continuously 1 time ever second.
What I need to happen, is the player press the button and when they press it, instantly it fires, not x seconds later. And I guess what I'm trying to do is 'limit' the fire rate to 1 time per second, not really 'set' it to 1 time per second. So the player presses the button 20 times in 2 seconds, they still only get 2 bullets. If they press it 1 time, they get one, and after an 'internal/global/whateveryoucallit' cooldown, THEN when they press it again, another bullet will come out. Most games i've played this is exactly how the fire rate works.
Is that possible?
edit: clarification
Create a rule in the shoot button that says:
Rule:
...When actor receives event Touch is Inside
AND
...When attribute game.Can Shoot is true
........Spawn bullet
........Change attribute game.Can Shoot to false
Then make another rule inside the shoot button that says:
Rule
....When Attribute game.Can Shoot is false
......Timer After 1 second
.........Change Attribute game.Can Shoot to true
Make sure the "Can Shoot" boolean is set to true when the game starts.
Hope that helps!
:^)
Thanks a ton for all your help!