How do you control rate of fire?

pjnolenpjnolen Member Posts: 152
edited November -1 in Working with GS (Mac)
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

  • jb15jb15 Member Posts: 602
    You want a timer attribute.

    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.)
  • pjnolenpjnolen Member Posts: 152
    How does the timer work in relation to 'pressing the button'? Pressing the button the timer cannot start at that point, otherwise the player is waiting x seconds for the bullet to spawn, which doesn't work. If it spawns automatically 'after' 5 seconds again then I don't need a button anyway and that doesn't work.

    Besides a timer setting what else do I need to do?
  • jb15jb15 Member Posts: 602
    Yes, just to clarify: You have three actors:
    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.
  • pjnolenpjnolen Member Posts: 152
    jb15 said:
    Yes, just to clarify: You have three actors:
    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.

    Ok, I created a new environment to create this scenario exactly. I set BulletFireRate to 1. Following every step I finished. When I press the 'button' to fire, nothing happens. If I turn off the 'otherwise change attribute game.Fire to false', then when i press the 'button' to fire, it begins firing 1 bullet every 1 second continuously.

    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
  • pjnolenpjnolen Member Posts: 152
    I'm using the 'Official Cross-Platform Controller Template' and it shoots as fast as you can press the button. Which is WAY too fast, I need a way to limit the number of shots that come out to reign in the dps without just increasing the hps of the enemy ships and not give the player cramps lol. I need to be able to slow it down, so I can give powerups to speed it up.
  • entersimonentersimon Member, PRO Posts: 273
    Create an attribute called "Can Shoot" and make it a Boolean.

    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!

    :^)
  • pjnolenpjnolen Member Posts: 152
    ok, looks like part of each of your suggestions worked. But the problem i was running into with using the official controls, was that everything was happening too fast, and I had to put in a timer to wait .01 seconds before changing the game.canShoot because it didn't have enough time to do it in those controls. lol

    Thanks a ton for all your help!
Sign In or Register to comment.