How do I make a cooldown on shooting

0 favourites
  • 9 posts
From the Asset Store
Shoot balls to destroy as many blocks as possible, at each stage the game will become more difficult.
  • I want to make it so that there is kind of a cool down on shooting so that you cant just spam the shoot button

  • Spawn projectiles using two conditions:

    'Is FireButton down?'

    and

    'every x seconds'

    then spawn your projectiles.

  • Thanks!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • the problem with using every X seconds is that you wont shoot right away when you click sometimes, which feel weird especially for longer delays (imagine holding down the fire key for 6 seconds then the bullet comes out).

    a better way to do it is to have a timer variable.

    every tick

    : add to variable object.shootTimer -> this.dt

    // this value gives you the time since the last shot fired.

    is fire button down

    is object.shootTimer > cooldown

    : shoot

    : set variable object.shootTimer -> 0

    // shoot the object, reset the cooldown

  • Might be better to have the action of firing set a variable, then every tick subtract from that until it reaches zero. That way you'll always fire the first time you press the button.

  • honestly it worked just fine since i just wanted to make it be able to shoot every .5 seconds

  • the problem with using every X seconds is that you wont shoot right away when you click sometimes, which feel weird especially for longer delays (imagine holding down the fire key for 6 seconds then the bullet comes out).

    Isn't that what they want? i.e. not to be able to fire at will. If you can always shoot right away, how is that a cooldown? Having said that, I usually use a Timer also. Or the Cooldown plugin.

  • codah, It only shoots right away if greater than cooldown time has passed, you wont shoot right away if you shot 0 seconds ago, you'll have to wait the length of the cooldown, but if you havent shot for 10 seconds, you wouldn't expect to wait possible the entire duration of a cooldown for your first shot.

    imagine you had a gun that could only shoot every minute, if you used every "60" seconds, then if the timer was at 61 seconds, and you clicked, you wouldn't shoot a bullet for a whole minute, and would have to be holding the key down for 59 seconds until you shoot, even if you haven't shot once. by using a variable, if your weapon is "cooled down" for the required length of time, then you don't have to arbitrarily hold down the key till the timer hits some value, you'll fire, and then youll have to wait, and youll fire again, etc. Reloading takes a set amount of time after firing your first shot in a series of shots, it doesn't make you wait a random amount of time based on the game timer before being able to fire.

  • codah, It only shoots right away if greater than cooldown time has passed, you wont shoot right away if you shot 0 seconds ago, you'll have to wait the length of the cooldown, but if you havent shot for 10 seconds, you wouldn't expect to wait possible the entire duration of a cooldown for your first shot.

    imagine you had a gun that could only shoot every minute, if you used every "60" seconds, then if the timer was at 61 seconds, and you clicked, you wouldn't shoot a bullet for a whole minute, and would have to be holding the key down for 59 seconds until you shoot, even if you haven't shot once. by using a variable, if your weapon is "cooled down" for the required length of time, then you don't have to arbitrarily hold down the key till the timer hits some value, you'll fire, and then youll have to wait, and youll fire again, etc. Reloading takes a set amount of time after firing your first shot in a series of shots, it doesn't make you wait a random amount of time based on the game timer before being able to fire.

    It's funny because I was going to write a post just like yours, then second guessed myself. I misinterpreted the way the Every x seconds worked in conjunction with something like Mouse: Left button down, or whatever. I guess I always user Timers anyway so I don't have this issue.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)