Bonsaiheldin Posted April 26, 2018 Share Posted April 26, 2018 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)); } Quote Link to comment Share on other sites More sharing options...
b10b Posted April 26, 2018 Share Posted April 26, 2018 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. Bonsaiheldin 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.