How do I shoot only one bullet

0 favourites
  • 8 posts
From the Asset Store
This pack contains 10 types of bullet effects, with different shapes and colors.
  • I want to shoot only one bullet when I press a key, and only after the bullet leaves the layout and is destroyed to shoot another bullet, how can I do this?

  • create a variable that gets set to one when you shoot or when the bullet is spawned, have the bullet destroy outside of layout and set the variable back to 0. create a condition on the key press/shoot event that only fires if the variable is 0.

    If none of that makes sense do the beginners tutorials and go through the manual first.

  • Cond: Bullet is on screen

    ELSE

    Keyb key is down: Spawn bullet

  • silkc2 - Exactly right

    However you could also:

    Keyb key is down

    (Sub) Cond: Bullet is NOT on screen: Spawn Bullet

  • Thank you very much! I used the variable implementation ideea. Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • silkc2 - Exactly right

    However you could also:

    Keyb key is down

    (Sub) Cond: Bullet is NOT on screen: Spawn Bullet

    That was first thing I tried, wouldn't work though (something to do with the event not firing if there are no instances of the sprite).

  • I suggest doing the number comparison, so hasfired=+1 when fired 1 bullet, and when the bullet is destroyed it sets hasfired=-1 so it's zero.

    This way you can setup multiple places where the bullet can be destroyed (on enemy hit) and speed up your firing like Megaman (megaman limited you to 3 bullets on screen, but if you were right next to an enemy or the screen edge you could spam bullets. A valuable mechanic for that game)

    If you want a specific delay on the firing rather than if the bullet is onscreen, you can do a timer system in which you can only fire every so often.

  • Well guys, there's more than one way to skin a cat but a friendly tip: You shouldn't really ever use variables unless you have to.

    I've already done it the same way I posted and works exactly as you'd expect (I'm making a gauntlet type game).

    Holding fire spawns a bullet. If it hits an enemy or goes off screen the next bullet spawns. This of course means you get the "faster" fire rate the closer your target, and when it's right next to you, basically bullet spam.

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