loader image

First-Person Weapon System (C#)

I developed this complete first-person weapon system featuring every type of gun, melee weapon, and object used for combat.

Scroll to
View More

mouse

Perhaps one of the single most important aspects of FPS games is their guns and weapons: while AI can make a game boring or challenging, the Weapon “feel” will make experienced players immediately feel at home or otherwise frustrate them. I put emphasis on creating weapon mechanics that would be equivalent to most AAA titles out there: weapon bob, sway, aiming, fire spread, weapon recoil, camera recoil, reloading, pellets, raycasting, shell ejection, hit particles, gun calibers, gun attachments, and more.

The base mechanics had to be covered: bullet raycasting, audio, muzzle flash, recoil, and reloading. From this, I kept adding more details. Notice the bullets ejecting from the gun as they’re being fired. I had to account for multiple weapon types and their different variations. For example, I created a base class called “FPObject” that would give basic functionality to any object that could be hand-held. From this, RangedWeapon and MeleeWeapon were inherited, as well as other objects (such as consumables and throwables). In this case study, we’ll focus on the RangedWeapon script.

But guns weren’t only made up of code: they consisted of art, visuals, and the sensation that a player was actually holding them. I textured, modeled, and animated a considerable amount of the weapons in-game. Some of the code helped with the aesthetics: I did the gun recoil animation via scripted animation (including the bolts and shell ejections), together with the instantiation of hit particles, muzzle flash, and the gun sounds. I also did the reloading and take-out animations in 3ds Max and then imported them into Unity.

The logic was also extremely flexible, using an assortment of variables to keep track of things such as the fire rate, damage, bullet impacts, compatible attachments, recoil amount, aim speed, reloading options, firing sounds, inaccuracy, inaccuracy spread over time, among many other options.

You can see a video of this system in action here: https://www.youtube.com/watch?v=KY6GatPM-Ik