Specialization - Gunplay
Time: 7 weeks, 20 h/week
The goal of my specialization was to create a third person shooting system with modular weapons. Part of the vision was to develop a generalized weapon system with easily interchangable parts that enable the rapid implementation of different firearms.
I chose to combine my specialization with Game Project 7. This effectively meant that I worked on the shooting and weapon systems of P7 during my specialization time. The benefit of this was that I didn't need to spend time on parts of the demo not relevant to my specialization, such as assets and animations, as I already had a project I could insert my specialization into.
The Weapons
An important part of my specialization was to create a weapon system that allowed for easy implementation of new firearms. I consider this part a success, as adding new weapons was much quicker and easier than I had planned. Once I had created my variables and functions I simply needed to change some numbers to create different weapon types. The only real effort i spent on making new guns was in the creation of unique behavior like that of the minigun.
The weapons I created were, in order: a revolver, shotgun, assault rifle, submachine gun, sniper rifle, and rev-up minigun.
I used Battlefield 2042 as a reference for the statistics of each weapon.


The Revolver
I began by creating the revolver as a base class for my weapons as it was a fairly versatile gun that would translate into the other firearms well. The first mechanic I added was shooting, in the form of a raycast that was visualized by a line. Next I added fire rate, then ammo and reloading. I also created a shooting range scene in Unreal Engine and exported it into our own engine to act as an asset gym to test my weapons.


The raycasting for gunshots. The blue ray is coming from the camera and goes along the camera's forward direction. The yellow ray is shot from the gun to the camera ray's collision point
The revolver's .json file
Weapon Characteristics
Each weapon's strengths and weaknesses encourages the usage of every one of them depending on the situation or the player's playstyle:
The sniper rifle has perfect precision and high damage at long range, but is slow and lacks sustained damage if the player misses.
The revolver has high accuracy and movement speed, but is outperformed by the sniper rifle at long range and the submachine gun at short range, and suffers heavily from recoil.
The assult rifle has a large magazine and great sustained damage, but doesn't boast the same opportunities for an instant kill as the sniper rifle or shotgun offers.
The submachine gun offers faster firing speed and movement speed than the assault rifle, but with a smaller magazine it gives less sustained damage.
The shotgun can kill an enemy in a single shot at short range and has comparatively little recoil, but is inaccurate and only offers two shots per magazine.
The minigun has the highest sustained damage and an immensely large magazine, but its slow movement speed, poor initial fire rate, and high inaccuracy forces the player to prepare for fights ahead of time and encourages a more defensive playstyle.
Reflection
I am satisfied with the selection of weapons implemented in the project. The core types of firearms are all covered, and they each offer a valid reason to use each of them. Moreover, the versatility of the weapon system allows for easy and rapid implementation of new weapons. The end result is a solid shooting system with a respectable selection of weapons that has room to grow and be iterated upon if more time is spent on the project.
Future Improvements
The most clearly lacking aspect of my work is the "game juice", the feeling of the shooting. Because I wanted to focus on implementing gameplay features I did not spend much time on the aesthetics or feedback of the gunplay. Adding something like health bars to show damage taken and otherwise generally polishing the feeling of the combat would improve the player experience significantly.
By implementing a way to inspect the stats of firearms and choose between them I could open up the possibility of creating many more weapons in a short amount of time as I could rely on the same systems that already exist for the weapons currently in the game.
To add more fun and variation to the guns I would also have liked to implement more unique weapons that behave differently from the existing ones.
Bullet Origins and Pointing Bullets towards the Crosshair
I made the bullets originate from the actual gun position rather than just the camera. The purpose for this is, for example, that if the player wanted to shoot out of a window but had the gun positioned below the frame, the ray from the gun would intersect with the wall. It also meant that blood splatter VFX could be angled along with the actual direction of the gunshots.
The way I accomplished this is by raycasting from the camera straight forward. If the camera ray would intersect with an object, a second raycast from the gun joint on the player mesh would be drawn to the collision point.
The Shotgun
The second firearm I implemented was the shotgun, as it was a good vessel for the creation and testing of the projectile spread system.
I was able to use the shotgun to test the inaccuracy variable by making the shotgun shoot hundreds of pellets at once, showing me the clear boundaries of where shots could spread to and how they were likely to distribute themselves.
.json Weapon Statistics Tool
In preparation for adding more weapons, I created a quick and basic tool in the form of .json text files. The purpose of this was to simplify the creation of new guns and to make it accessible for designers without them needing to access the code.
After the first time a .json has been read the program converts it into a binary file, meaning that the game loads the files faster after it has been run once.
Assault Rifle, Submachine Gun, and Sniper Rifle
Implementing the assault rifle, submachine gun, and sniper rifle was much quicker than I had expected. By this point my weapons were versatile enough that creating new weapons simply meant using the .json tool to change some variables.
In order to add differentiation between the weapons I added a movement speed modifier when the player is aiming. The revolver and submachine gun only slows the player a little, while the sniper rifle punishes movement heavily.
The Minigun
The final and most unique weapon I added was a rev-up minigun, which meant I needed to add a system for increasing a firearm's shooting speed as it fires. I also made it start spinning/revving up instead of aiming when the aim button is held, meaning it always hip-fires.
Recoil and Inaccuracy
Because I wanted to create a shooting system that would be applicable to both third person shooters and first person shooters I decided to go for a hybrid approach when it comes to recoil. When the player hip-fires, bullets are spread in random directions. However, if the player is aiming, the camera shakes instead.
This creates a versatile recoil system that can be used in most types of games. Because it is made of two parts it would also be possible to use only spread or only camera shake if a game wanted to use a single system. P7 only uses camera shake, for example.
Spread Recoil
When the player shoots while hip-firing, the angle of the spread inaccuracy grows. The code for the bullet spread is a fairly simple randomized alteration of the projectile's direction.
After the player stops firing for a while, the spread recoil recovers exponentially. The recovery scales with the recoil per shot, meaning that the sniper has higher recoil recovery because it has high recoil.
I used Geogebra to set up a graph function to calculate how fast I wanted the recoil recovery to be. This showed me how much recoil the player would have depending on how many shots they fired, and how fast it would recover.
Future Improvements
Adjusting one's aim to keep the crosshair on a target while the recoil is kicking around the camera can sometimes feel disorienting. This is the most obvious part of the recoil system that requires fine tuning and polish. The interaction between the camera shake and the player input could be improved, and it would also be nice if the camera would lower itself again after the player has stopped firing. However, this would need a lot of tweaking to get right as I would need to account for the player's mouse movement and how it interacts with the recoil. Although I decided to focus on other tasks for my specialization, further work on the camera shake recoil would be necessary to deliver a quality product.
The graph I created in Geogebra to calculate the spread recoil and how accuracy recovers over time.
The camera shake is randomized, but a skilled player can adjust their aim to still hit their shots.


Camera Shake recoil
The player suffers no bullet spread inaccuracy when it is aiming. Instead, the camera jumps randomly upwards and horizontally. The camera shake is randomized between 0.5x-1x the max vertical jump variable upwards and -0.5x-0.5x the horizontal.
Although some games use spread patterns for weapons, I chose to make the recoil completely random as it provides a more dynamic experience. While random recoil gives more of a challenge when attempting to hit a target, it is still predictable enough that a skilled player can adjust their aim to maintain their precision.
Accuracy when Moving or Hip-firing
When the player moves or hip-fires it has lower accuracy than when it is aiming, depending on the characteristics of the held weapon. For example, the revolver and submachine gun are far less punishing than the sniper rifle.
Syncing the HUD with Accuracy
In order to sync the player's accuracy with the crosshair, I made a version of the shotgun that shoots projectiles that go in the cardinal directions of the player's recoil. Thanks to this I was able to adjust how separated the crosshair was by studing how the projectiles lined up with the HUD.
Credits
Because my specialization uses Game Project 7 as a base I want to give credit to my team. I developed the player and all features discussed in my specialization by myself, but the engine and features not relevant to the specialization project was developed as a group. Without my team I would be sitting in Unreal Engine with nothing but cubes and cylinders, so I am very grateful that I was able to work on my specialization parallel to P7.


dexter@abrisius.se
+46 72 172 70 66