Balancing powerups with enemies

Hal Brooks
3 min readJul 25, 2021

Objective: Balance the powerup spawn rate with the enemy powerup spawn rate in Unity

Game excerpt showing relation between ammo and enemies.

The first thing to do is to calculate the enemy spawn rate. There are five possible enemies with an equal chance to spawn every 3 seconds. However, one enemy has a shield so this enemy has a spawn rate of 0.067 /sec, and takes two shots to kill. That means the player needs at least 0.4 shots per second to stay even assume 100% hit rate.

Shots by player required to stay even

Initially all power ups were in one IEnumerator function, but this dilutes the chance for ammo spawns. Play testing proved that being constantly out of ammo was very irritating to the player . The excerpt below shows how to split out the ammo spawns from the other powerups to provide ammo more reliably. Both use the same [SerializeField] private float _powerupSpawnRate variable to control spawns. This variable can be adjusted in the inspector.

Splitting out ammo spawn from other powerup spawns in SpawnManager script.

Now both powerup types have the same spawn rate, each with three types, but there is a random element to their generation. So ammo powerups should spawn every 10–21 seconds.

Spawn rates for powerups in seconds.

The three types of ammos do not spawn equally. The table below shows their relative spawn frequency, which will be used to calculate the player fire rate.

Ammo type spawn frequency in seconds.

Since the ammo limits the rate of fire, the player fire rate is calculated based on the number of shots that can be fired based on each power up. Each powerup provides different levels of ammo, laser or ammo powerup is 15 ammo, triple shot powerup provides 15 ammo after the 12 potential free shots, and missile powerup provides just two shots. The table below shows these fire rates.

Fire rates for different ammo types.

Since random distributions will generate dry spells for ammo the Min fire rate is summed to calculate the player’s fire rate of 0.77 / sec. Given the required hits to clear enemies is 0.4 /sec then this requires a hit rate of just 52% for the player to stay even when the ammo powerups are sparse. Using a _powerupSpawnRate of 15.6 seconds should be challenging for the player, while feeling possible, but can be easily adjusted during play testing.

--

--