Sign in to follow this  

How do turrets in games fire in salves / volleys (not at the same time)?

Recommended Posts

This is a very general question about games where someone or something shoots bullets. I try to describe it the best i can. My picture might help, too.

You know, there are games where you have ships with their turrets firing their bullets or lasers or whatever.

But the turrets don't fire at the exact same time, even if they're all ready and have the exact same reload speed. They fire with a short delay in between, making the bullets form cascades or salves / volleys. The delay also is not just a random number but predictable.

This allows for continous shooting without pause. An example of a game where this happens is Space Pirates and Zombies (the missiles).

Does somebody know the mechanic behind this? I guess it's pretty trivial once you got it. 🤔

My own theory is that when the fire event happens, a shot fires and then the next turret has a slightly higher shootNext timestamp.

But i can't get my head around how to code that. 😣

EDIT: What works a bit, is the following piece of code (using Phaser 2, Javascript). Though it makes my turrets just switch between shooting in volleys and altogether. 😰


if ( >=
{ = + + (i * (dbWeapon.rate / numberOfTurrets));


Share this post

Link to post
Share on other sites

Modulo Operations can be useful for offsets like this.  It might work that each turret has its own "seed" (e.g. 1...12) .  Then, each game-loop tick, increment an "updates" counter.  Then lastly only consider firing if "updates%12=seed".  Using unique prime numbers for the seeds can help make any emergent patterns more varied, or use consecutive seeds for quick succession.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.