Jump to content

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


Bonsaiheldin
 Share

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. ?

Quote

if (game.time.now >= weapon.data.shootNext)
{
    weapon.data.shootNext = game.time.now + weapon.data.rate + (i * (dbWeapon.rate / numberOfTurrets));
}

hooooooow.jpg

Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...