Fire one bullet at a time on keydown

0 favourites
  • 12 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • Hiya

    I think this should be simple but can't work out what I am doing wrong.

    On spacedown I want to spawn a bullet, but only allow one on-screen at the same time (so fire rate increases if shooting something nearby).

    I thought this would work but it doesn't:

    * NOT Bullet on-screen

    * Spacebar down

    = Spawn Bullet

    Nothing happens.

  • The problem with that is that it will keep spawning bullets if there's any bullet off-screen.

    You could have:

    Bullet: Is on-screen
    
    Else
    Keyboard: Space is down
       -> Create bullet
    

    or give your bullet 'destroy outside layout' behavior and only fire when

    Bullet.Count = 0

  • Actually it's not firing any at all, and I do have the bullets set to destroy outside layout. So as far as I can see my logic *should* work.

    Yours looks to be identical logic done in a different way but I'll try it anyway.. thanks. :)

  • Yeah your way works, thanks! I have to say I don't fully understand why mine doesn't work, I can't see a logic error. Do you think it should be recorded as a bug?

    * NOT Bullet on-screen   < is true!

    * Spacebar down   < is true!

    = Spawn Bullet < doesn't happen!

  • Oh yeah, if there are no bullets the first condition will be false.

    I guess it's kind of confusing but "Bullet: NOT on-screen" will only be true if there are bullets that aren't on the screen.

  • But that's my point, it isn't confusing at all. I inverted the statement to be a NOT condition, thus the question;

    "There are NOT any bullets on the screen" should return true.

    I'll submit as a bug just to see if it's me being silly or not. I hope not after 20 years of programming, lol. :)

  • Wouldn't it make more sense to have a variable on whatever is shooting and have it be false when the bullet is made and true when you can fire, so you would have something like.

    On space down

         Variable = true

               < call.function(shoot)

                     Function shoot = spawn bullet & set variable to false.

    then have.

    On bullet destroyed < set variable to true.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yup that would work too, though it's debatable if it makes more sense to do it that way ;)

    I've reported a possible bug with the "negative on-screen" check and am using ramones "else" approach in meantime.

  • "There are NOT any bullets on the screen" should return true.

    See it's not really "There are NOT any bullets on the screen", it's more like "There are (one or more) bullets that are not on the screen".

    You're not asking "are there no bullets on the screen?", you're asking "are there any bullets not on the screen?".

    It's like the condition "Player: NOT Platform is moving" will be false if there is no player object. It's not "are there no players moving?", it's "is any player object not moving?".

  • * NOT Bullet on-screen

    * Spacebar down

    = Spawn Bullet

    Nothing happens.

    Did you destroy all bullets outside layout first - before the Bullet NOT on Screen Condition? (Specifically you want to destroy the bullet sprite stored offscreen) otherwise Bullet NOT on screen will always return TRUE

  • Bullet behaviour should cause them to destroy outside layout, and I'm not sure when behaviours are triggered.

    According to a dev it's always returning false, because there are no instances of a bullet for the engine to check the rule against in the first place.

    Anyway it just doesn't work this way, so I can use the else or I can use bullet count.

  • try

    (event)on key down -> (Action) spawn "bullet" at "object" point "0"

    ------------------------------------------------

    (condition) Every X seconds

    X will be the time between each bullet.

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