How do I make a turret fire multiple bullets per shot?

0 favourites
  • 3 posts
From the Asset Store
Shoot balls to destroy as many blocks as possible, at each stage the game will become more difficult.
  • Hey everyone, how’s it going?

    I’m making a game using turret behaviors, and I have a question I’d like your input on. When a turret is able to shoot (“on turret shoot”), I want to set up a system where each shot can create a specific number of bullets. To be clear, I'm not referring to the number of shots, but rather the number of bullets created per shot.

    Currently, I’m using a loop to create bullets based on the number of shots the turret has. For example:

    On turret shoot
    ->for 1 to numberOfShots
    -->create bullet object
    

    But I’d also like to configure a specific number of bullets per shot. Here are a couple of examples of what I'm aiming for:

    Turret A has 2 shots, and each shot creates 1 bullet:

    (turret)
    (shot) (shot)
    

    Turret B has 1 shot, and each shot creates 2 bullets:

    (turret)
    (shot)
    (shot)

    Let me know if this makes sense, and if you have any ideas on how to implement it!

    Tagged:

  • But I’d also like to configure a specific number of bullets per shot.

    You can add another nested loop:

    On turret shoot
     for 1 to numberOfShots
     for 1 to numberOfBullets
     -->create bullet object
    

    Also use instance variables on turrets.

    You can spread shots and bullets, for example:

    On turret shoot
    ..for 1 to numberOfShots 
    -->Wait (loopindex-1)*0.3
    
    ....for 1 to numberOfBullets 
    ----->create bullet object
    ----->Set bullet angle to self.angle+random(-5,5) degrees
    

    The shots will be fired with 0.3s delay between them, and bullets will fly in 10 degrees cone.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks, dop2000! I was trying with a variable, and I thought it would be more efficient the way you did it. I also added the scatter value to create the possibility of making weapons with imprecise bullets. I'm thinking about whether I can use the same code to make bullets like a shotgun.

    + System: For "shotCluster" from 1 to dictionary_playerWeaponsAttributes.Get("shotCluster")
    -> System: Wait (loopindex-1)×0.1 seconds
    ----+ System: For "multiShot" from 1 to dictionary_playerWeaponsAttributes.Get("multiShot")
    -----> System: Create object dictionary_playerWeaponsAttributes.Get("bulletName") on layer weapon.LayerName at (weapon.X, weapon.Y), create hierarchy: True, template: ""
    --------+ System: Pick last created playerBullets
    ---------> playerBullets: Set Bullet angle of motion to weapon.Angle + loopindex("multiShot")×4 + random(-dictionary_playerWeaponsAttributes.Get("scatter"),dictionary_playerWeaponsAttributes.Get("scatter")) degrees
    ---------> playerBullets: Set Bullet speed to dictionary_playerWeaponsAttributes.Get("projetileSpeed")
    ---------> playerBullets: Set FINALDAMAGE to Functions.calculateBulletDamage ( dictionary_playerWeaponsAttributes.Get("damageType"), dictionary_playerWeaponsAttributes.Get("baseDamage"), dictionary_playerWeaponsAttributes.Get("projectileWeaponDamageMutiplier"), dictionary_playerWeaponsAttributes.Get("laserWeaponDamageMultiplier"), dictionary_playerWeaponsAttributes.Get("blasterWeaponDamageMultiplier"), dictionary_playerWeaponsAttributes.Get("projectileExplosiveWeaponDamageMutiplier") )
    ---------> playerBullets: Set bulletDistanceTravel to dictionary_playerWeaponsAttributes.Get("bulletDistanceTravel")
    ---------> playerBullets: Set piercingEnergy to dictionary_playerWeaponsAttributes.Get("piercing")
    ---------> playerBullets: Set explosionSize to dictionary_playerWeaponsAttributes.Get("explosionSize")
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)