Final Project Week 7 & 8 - Bullet Spread


This blog will cover week 7 and 8 as they were both working to create features that are all related. I have been focusing on creating the bullet spread mechanics as well as the crosshair mechanic that will work in tandem with that.

Looking At Other Games

Before I started making my bullet spread mechanics, I looked at some games to see how their systems work so that I know what I want to create by looking at which features I want to implement into mine. Here I will quickly show what stood out to me as features that I wanted to add, and some that I didn't want to add.

Battlefield V

In Battlefield V (2018), the spread is quite small in the majority of weapons. Below I have recorded some clips and I will compare the variations of spread within the game. Overall it appears that the difference between spread on different weapons includes the minimum spread and the spread increase per shot. I didn't notice a maximum crosshair size as it only stopped growing when you ran out of ammo. Another feature that this game and the others have included is screen shake and recoil. I will analyse this further in a later blog but in this post, I am focusing solely on the bullet spread and crosshair.

This gun has a very tight spread to balance out its a slow rate of fire. A side effect of its rate of fire is that it barely grows the spread because it will grow then shrink before the next shot is taken. This was most likely done on purpose by the weapon designers.


This gun has a lot more base spread and its fast rate of fire means that it has a much larger spread increase over time. This would have been done intentionally as the weapons were designed and the increase in the spread would have been set to balance out the higher fire rate of the gun.

In my system, I would like to implement the minimum spread and the spread increase variables, however, I would also like to add a maximum spread value to give the developer some extra options.

Titanfall 2

Titanfall 2(2016) has a random spread much like Battlefield, however, they utilise their crosshair differently. They use the spread of their crosshair as a way to balance weapons, as well as the bullet spread. This allows them to give the players the fast-paced experience that they expect from the game while also being able to balance the weapons.

This gun has a very accurate hip fire, however, the crosshair is spread out a lot more, this is to increase the difficulty of lining up shots with the hip fire. On some weapons, they will also remove the dot in the centre of the crosshair. The reason they have done this is to balance the weapon while allowing the fast-paced nature of the game alive as the players will have to aim down sight less frequently.

This crosshair more accurately represents the actual spread of the weapon, but this shows that the game has different types of crosshairs for different types of weapon. While this is a feature that I would like to add into my system, I feel like this is not essential to the bullet spread system. If I get time towards the end of my project I would like to add this into my system.

The features I would like to add into my system from Titanfall 2 is the ability to have an offset in the spread of the crosshair vs the bullet spread.

Counter Strike: Global Offensive

Counter Strike: Global Offensive (2012) has a very different spread system to the other examples, it uses spread patterns which are all predictable meaning that the spread will be the same every time you shoot the gun, this means that the crosshair is less important to the more experienced players as they will already know exactly how the bullets will hit before they shoot. This means that the game has a very customizable crosshair system where the user can change almost anything about the crosshair including colour, size and shape. Below I will show some clips of hip firing in the game to show the bullet spread.

The spread of the bullets for all guns in this game is completely disconnected from the crosshair, however, for this gun, it will act the same way every time you shoot.

Here you can see that the crosshair behaves exactly the same as in the first example, but the spread pattern is different. As the last example, however, the pattern of this gun will be the same every time you shoot.

The only thing that I would like to take from this system is having a static crosshair option for developers that would like that for their game.

Implementing Simple Functionality

I started by making a simple bullet spread system because I knew that once the main functionality was in place, I would be able to create the crosshair system and modifiers to the bullet spread. The first thing I had to do was switch how the shots positions were being calculated. I am still using ray casting, however, I have changed how the positions of the rays are calculated.

Originally I was spawning a ray from the position of the camera, pointing forward relative to the cameras transform. What this means is that no matter what, the ray will hit the object in the centre of the screen. I was thinking about simply setting an offset for the start position of the ray to get bullet spread, however, I knew that this would cause issues with the crosshair functionality later, because of this.

Old method New method with the spread



The new method that I implemented uses Unitys "Camera.ScreenPointToRay()" function (Unity Technologies, 2019), this takes a Vector2 that will correlate to the screen position that you want to fire the ray from. With this, I am able to exactly match the spread of the bullets and the distance between each point of the crosshair so that what the player sees is the correct information.

Normalising the Spread

Now that I had the main functionality of the spread created, I realised that there was an issue with the diagonal spread being a lot more than the vertical and horizontal spread. I was able to find a simple fix to this. Instead of taking the random position of the spread and multiplying it by the max spread value, I had to take the random position, normalise it, then multiply that by a random value between 0 and the max spread. What this means is that the max spread will never be more diagonally, that it is vertically or horizontally making the system a lot more intuitive for the players.

Without Normalisation With Normalisation

Preparing for Multiple Screen Sizes

The next thing I changed I knew would be an issue as soon as I decided to use the screen position to calculate the rays for shooting. At this point, I was using pixel amounts to control the amount of spread. The issue with this is, if you increase the resolution of the screen, the spread will be a lot less than if you play on a lower resolution. to fix this I changed the system to use a percentage rather than the pixel amount. using this the developer is able to set their spread equal to how much of the vertical screen they would like the spread to use. For example, if they set the spread to 50, the circle of spread will have the circumference of 50% of the vertical screen size.

10% Spread 25% spread

Increasing Spread while Shooting

The feature I liked most about Battlefields hip fire system is that the number of spread increases as you shoot. The speed of this varies between different weapons meaning that while a gun may have good base hip fire spread, it could quickly increase as you shoot. Some guns, however, are made to be hip fired and will barely increase the spread. I would like to implement this into my system.

Without Spread Increase With Spread Increase

I have added some values for the developer using the system, these are, minimum spread, maximum spread and spread increase speed. This will allow the developer to have a lot of flexibility and create different experiences between weapons.

Slow Increase Fast Increase

If the speed is set to 0, the spread will always stay at the minimum value, however, I will be adding a separate setting into the custom inspector I make at a later date that will make it a lot more intuitive for the developer.

Creating the Crosshair

All of the games I have looked at have a crosshair, they are different for each different weapon, In Battlefield, this is because the crosshair shows exactly how much spread your weapon has, however in Titanfall, each weapon has a different crosshair size independent from the actual spread of the weapon that they set to balance different weapons.

First I will create a simple crosshair mechanic that will simply have a static crosshair that the developer can set the size of. A really simple but inefficient way to do this would be to create a different sprite for each size and give the user to choose one. This would increase the size of my assets and would be less modular than a more efficient system. The most effective and efficient way to create the crosshair is to dynamically create the crosshair at run time. This way the user can input any distance and the crosshair spread out to match that exact distance without the need for separate sprites. This system would only require 1 sprite that will be used for the lines in the crosshair.

Static Crosshair

Next, I moved onto having the crosshair match the spread of the gun. Doing this is quite simple because of the method I used to calculate the spread of the shooting. I can use the same value that the weapon system script uses to calculate the spread. This means that implementing this just required having the crosshair script find the value in the weapon system and setting its spread to that.

Dynamic Crosshair

The last feature I wanted to add is an offset, this can be used to change the difficulty of a weapon or to change the feel of a game. This is used in Titanfall where weapons with really low weapon spread will have a large offset to make it harder for the player to line up hip fire shots. This feature takes the dynamic system implemented before and adds a percentage offset to the amount of spread.

Dynamic Crosshair With Offset

Spread While Aimed

The system for aimed bullet spread is not as complex as the hip fire system. What I have done, is have a single separate value for spread while aimed. From the games I tested, none had bullet spread while aimed, however, I know that there are some that exist. because of its rarity, I didn't want to spend too much time over complicating it.

No Aimed Spread Large Amount of Aimed Spread

Next week I will begin working on implementing recoil into aimed shooting in my system.

You can find the project here: https://github.com/ElliotChester/Modular-Weapon-System-Final-Project

References

Unity Technologies. (2019). Unity - Scripting API: Camera.ScreenPointToRay. [online] Docs.unity3d.com. Available at: https://docs.unity3d.com/ScriptReference/Camera.ScreenPointToRay.html [Accessed 8 Feb. 2019].
Counter Strike: Global Offensive . 2012. PC [Game]. Valve Corporation

Titanfall 2. 2016. PC [Game]. Respawn Entertainment

Battlefield V. 2018. PC [Game]. EA Dice

Comments