#7 | (WIP) Blaster System


Hello!

Since the last devlog, I've made more progress on the blaster system. Despite what I said in an earlier devlog, I'll be sharing some snippets of code alongside videos to display the progress I've made. Brace yourselves, this log is gonna be a long one.

So far, I've created a very rudimentary inventory to store the players blasters, a system to switch between them and data containers to store info for each unique blaster.

To switch between different blasters in their inventory, the player can press keys 1 to 9, including 0. When the player equips a blaster, local variables (FPS, fire rate, fire mode) change to match those of the equipped blaster.

Earlier, I mentioned data containers. Scriptable Objects are data containers in Unity, they can be used to store all sorts of data like numbers, text or images. I used these to store the info for different blasters.

The nice thing about Scriptable Objects is that I can easily duplicate them and change their variables, creating new blasters with ease.

Although not necessary to understand how this entire system works, I'll explain the logic behind switching between blasters and how each fire mode works. If you're not super nerdy like I am, you can skip this and not miss anything critical.

First, let's go over the logic that determines what happens when the player presses the fire key. The comments in written in green are a summarized explanation of how the code works.

This may look daunting to some, so lets break it down. When the player presses the fire key and has a blaster equipped, the game checks if the player is allowed to fire and has ammo in their magazine. If those conditions are true, the game checks the equipped blasters fire mode. Finally, depending on the equipped blasters fire mode, the player fires their blaster.

Next, I'll explain the different fire modes and how they work.

The manual fire mode is quite simple. When the player presses the fire key, a projectile is spawned and there is a delay between when the player fired and can fire again.


Next up is the semi-auto fire mode. As long as the player has ammo in their magazine, they can fire as fast as they can press the fire key. In this case, the float "fireRate" would be set to zero whereas in the manual fire mode, it would be set to 1 or 2.


Here's the most fun fire mode, full-auto! While the player holds down the fire key, a projectile is spawned and their magazine is decremented by one (just like the other modes). The float "fireRate" is set to a number less than one. For example, it could be set to 0.14 for a fire rate of 7 rounds per second.


Lastly, a niche fire mode, burst fire. When the player presses the fire key, three projectiles are spawned in quick succession, a burst of fire. I'll edit this mode at a later date to include a variable for how many rounds are fired in succession for more customizability. Personally, I haven't found much of a use for burst fire in the real life games I attend. But some people like it, so I'm including it in this game.

I'll also be adding an addition to the manual fire mode, slam-fire. In layman's terms, when you hold down the trigger and cycle the action, the blaster fires after the cycling is finished. When I add this mechanic, the player will be able to hold down the fire key, in the manual fire mode, to continuously fire (albeit with a longer delay than the other fire modes).

For those read to the end, thanks for endorsing my nerdiness. I'll be working on this system and the inventory / shop systems over the rest of my holidays.

Thanks for reading!

Get HvZ - 2D

Leave a comment

Log in with itch.io to leave a comment.