Last week we began discussing having various weapons in our game, so we decided to have them as a sort of “Temporary” upgrade. Currently the player starts with just a pistol. It has a medium fire rate, basic 1 shot pattern and the projectiles move at a somewhat normal pace. On top of this, since it is the starter weapon, it has infinite ammo as well.
Marcus mentioned something that was already on my mind, which was that we should have weapons that have unique patterns that offer new gameplay aspects. After some discussion with the team, we decided to have a simple test weapon to see how the concept would handle, so I decided to do a shotgun. The weapon handles just like one would expect: It fires several bullets in a somewhat wide cone spread, slow rate of fire and unlike the pistol, it has limited ammo.
Currently, the shotgun is a derivative of the pistol, which acts like the overall prefab for all current and future guns. The weapon is setup to have a current ammo count, overridable firing function and fire rate setting. Whenever I pick up a weapon, it runs through all the player children to see if there is an already existing weapon. If there is, it will remove it, then position itself over the player and apply to become a child of the player.
- The ammo count is set to be -1 by default. The reason I do this is to quickly indicate that the weapon is running on infinite ammo instead of having to rely on a separate value. It doesn’t cause any issues since I only check the “Take away ammo” function as long as your ammo is above 0. Alongside with this, I made the ammo counter show up below the crosshair, since most of the time, the player will be looking at where he is aiming making it easier for him to focus on how much ammo he has left.
- The overridable firing function allows me to quickly make a new fire pattern should I require it. As mentioned, I already have a shotgun spread pattern which I simply made by running a “for loop”, each iteration giving a new aim angle for the projectile.
- The firing rate ties in directly with the fire function, since I need it to make proper unique firing patterns, such as a slow firing sniper rifle which penetrates through enemies or a fast firing light-spread assault rifle.