Cooldown Systems

Ahad L. Amdani
3 min readMay 17, 2021
Throttled the fire rate with a cooldown system

In Sovereignty, we don’t really want to allow unlimited/infinite and no-lag weapons fire. Therefore, we need to enable a Cooldown (CD) on player input of the weapons that are capable of being fired.

For the primary weapon, we track input with the spacebar with a limited cooldown of 0.15s.

After further refactoring, this method will be for the primary single-shot laser, which can eventually be upgraded to a double-shot laser. In addition, the goal is to have three weapons systems — primary (lasers and twin lasers), secondary (various kinds of missiles), and auxiliary (special weapons, such as EMP bursts, space mines, and ion weapons that can disable shields). I’m also interested in a once-per-minute ult that they can leverage as an ace up their sleeve. Although, I’m still determining what an appropriate input scheme should be — do the users swap between systems and always fire using a single key? After considering this for a bit, I decided to go down the path of the MOBA — QWER! Of course, we’re using W as an alternate to move up, so we’ll use spacebar for primary weapons, Q for secondary weapons, E for auxiliary weapons, and R for the ults. This way a user can press four “weapons” keys simultaneously, allowing for some interesting combinations. That being the case, I expect to see the variables actually be _canFirePrimary, _canFireSecondary, _canFireAuxiliary, and _canFireUltimate. The _fireRates would probably also have to include the weapon system in the names. This is what it looks like afterwards:

Maximum customizability?

Then, that being the case, let’s update our weapons input tracking methods:

Everything in its place

Beyond this, the logic is fairly similar and straight forward per ability/weapons system: check to see the appropriate key has been pressed and that the game time exceeds the previous cooldown offset, then instantiate an instance of that weapons systems’ prefab with appropriate position offset and direction/velocity.

I mean, we could refactor since they look so similar, but I’ll probably change offsets and velocities and such.

So all we have to do is make sure that the appropriate weapons prefabs are set on the player object, or add in some logic to disallow firing if they haven’t yet “picked up” or “earned” the other weapons systems (meaning that the prefab is currently set to null).

Not pictured here, the other weapons input trackers have the same kind of conditional guard for now.
At least have that primary laser weapon set! Don’t want to leave our ship defenseless…or do we? 🙊

--

--