-SOLVED-Random bullet from turret

0 favourites
  • 4 posts
From the Asset Store
This pack contains 10 types of bullet effects, with different shapes and colors.
  • Hello everyone.

    I have a peculiar situation at hand. I crated a sprite, gave it turret behaviour, added two different bullet sprites (red and green) and want the turret to shoot a random bullet each time. (there is also an irrelevant trick where turret shoots in irregular intervals as you will see.) Below is what I came up with:

    global variable what to shoot = 1

    cond:

    on turret shoot

    whattoshoot = 1

    act:

    create object redbullet on layer 1 at enemybird image point 1 x and y

    play sound

    set redbullet angle to enemybird.angle

    set turret rate of fire to 4-random(1,2.5)

    set whattoshoot to round(random(0.9,2.1)

    cond:

    on turret shoot

    whattoshoot = 2

    act:

    create object greenbullet on layer 1 at enemybird image point 1 x and y

    play sound

    set greenbullet angle to enemybird.angle

    set turret rate of fire to 4-random(1,2.5)

    set whattoshoot to round(random(0.9,2.1)

    supposedly the enemybird will either shoot a green bullet or a red bullet, then random will create between 0.9 and 2.1 and round will change it to either 1 or 2. so next time relevant bullet will shoot. And it works! But sometimes, it shoots both bullets together. There is no other event outside of these related to turret behaviour or bullets. Does anyone have any idea what I could be doing wrong?

  • Wait, why are you declaring whattoshoot so far down the list of actions. Surely it should be set first, as the shooting action takes place?

    I.e.:

    On turret shoot -> set whattoshoot random etc.

    sub-events:

    whattoshoot = 1...

    whattoshoot = 2...

  • Geometrix, I moved it up but it didn't work either. Though I really don't know why I couldn't think of doing it the sub-evet way. I started only couple days ago, so fresh... Thanks for the help, I will try it that way.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It worked! Thanks Geo!

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