DevLog26: Ammo And Reloading

I added a ammo and a reloading system similar to the game Overwatch.

The player has a high rate of fire with the draw back of having to reload when empty. There is also a cooldown to reload so that the player cannot continuously press reload and shoot.

The bars that fill and deplete underneath the numerical bullet amount represents the completion time of the reload and the reload cooldown.

The top bar is the reloading cooldown. The player will not be able to reload until the bar is depleted.

Below is a another visual representation of the player reloading. Its a progress bar for the ammo filling up.

Reloading can be interrupted at any time. In doing so, the player will only be able to shoot the amount of bullets that was loaded in.

Max ammo can be infinitely increased by grabbing these paydirt icons. The time to reload is time dependent so reloading time will remain the same no matter how large the player’s ammo is.

Reloading The Ammo

A coroutine was made to handle reloading itself.

I needed to keep in mind that the ammo could expand to a ridiculous number. So I converted the rate of the reload to a percentage of 0–100. Also insuring that a integer number is added.

The slider that the reload communicates to has a min value of 0 and a max of 1; Representing 0–100%.

Reload Input

Reloading is done by pressing R. Pressing R will check ifthe player is already reloading, if the ammo is not full, and the reloading cooldown is finished.

If all correct, it’ll set the reloading timer, state that the player is reloading and start the coroutines.

interrupting reloads

Interrupting the reload and having the cooldown remain is easy.

we just simply state that the player is no longer reloading and insure that the reloading bar is emptied. Setting _isReloading will stop any form of reloading operation aside from the reloading cooldown.

This is placed within the firing button of the player. So whenever the player is firing, it is also constantly stating that the player is no longer reloading.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store