2. FPS GAME - WEAPONS
The player's arsenal.
The idea was for the player to have 9 weapons in total, one for each number on the keyboard (except for the 0 key 🙁). But then, thinking about it, it felt unnecessary and bloated and would be harder to make them all useful without the next weapon making the previous obsolete. So I cut it down to 7, and then 6. I want the player to use all weapons in the game, not just one or two, where they just keep switching to their favourites. Helping with that is the amount of max ammo the guns are going to have as well as the amount of ammo pickups in the world. Every weapon in the game can also be upgraded/leveled up. So only using one weapon in the game can really make the game more difficult for the player in later levels.
Each weapon starts at level 1 and their max level is level 5 (TBD - might shorten it to 3). Haven't decided what makes your gun level up yet. Initial thinking was that it just counts the enemies you've killed with each gun, and based on that it will level up at a certain amount of kills. The weapon's damage, fire rate, and enemy hit chance increase with each level.
I've created tables in Microsoft Excel for each weapon that stores their level values that is read by a script in the unity editor (and in-game). This makes it much easier for me to edit and tweak individual values at anytime.
Each weapon also carries a set of values that modify a Box Collider that is used to check if the player's attack has hit an enemy. So if an enemy is inside the box collider and nothing is blocking the player from attacking the enemy, then the player's attack hits the enemy!
Some weapons may use this box collider to aim at enemies. For instance, the player shoot a fireball, which is a projectile, if the enemy is in the collider, then the projectiles direction will be where the enemy is in the world, and move towards that.
Weapon sprites were all made in Photoshop, with the help of a Wacom Pen & Tablet. Took photos of myself (my hands 👐) holding placeholder objects as reference. The spear was a roll of Christmas wrapping paper! 🎅🎁
When an enemy walks into the Player Attack Box Collider, the enemy is added to a list that keeps track of every enemy in that collider. So if the player shoots the shotgun, it gets all enemies in the collider and damages all of them. The shotgun's damage is also higher when the enemy is closer than half of the Player Attack Collider size (closer to player), otherwise its the damage output is low. If you use the Spear, it only damages the enemy that is closest to the player (only one enemy at a time).
I still need to code the weapon hit/miss chance when attacking. So far, if the enemy is in the attack box collider, and the player attacks, it hits the enemy 100% of the time. Might be interesting if there's a chance you can miss as well.
The weapon attacks are all controlled by one script (a script called WeaponAttack.cs). So far, I have created 3 of the weapons. Fists, Spear, and Shotgun (there was a Dagger, but it was replace by the Spear). The Fists and Spear use the same bit of code that's under the function called MeleeAttack(). It attacks one enemy at a time. The Spear has a greater reach. The Shotgun uses a function called SpreadShot() in the same class.
Your comment will be posted after it is approved.
Leave a Reply.