Final Project Week 4 - Aiming Continued


In the last blog I began working on the aiming mechanics for my modular weapon system. I managed to get the core functionality of aiming in, this blog is covering the past 9 days instead of a week because I didn't have as much time to work during the week due to other modules taking up more time. In this blog I implement the more advanced features of the aiming as well as some of the modularity that will comes with it, including aiming relative to rotation and multiple sights.

Aiming Relative to Rotation of Sight

I started this week improving the way the weapon is positioned on the screen when rotated. The code I implemented last week allows the developer to set a custom rotation for their weapon while aiming. This was originally added to allow the developer to have a scope at an angle, however, after some thought, I have decided to change how I handle that.

The issue with the old method was that if you changed the rotation of the weapon, you would need to set the offset of the scope dependant on that. This was a major issue because it takes a lot from the modularity of the system. What I wanted the system to do, is have an offset on each sight, this would then allow the system to set the positioning automatically based on the rotation of the weapon and a sight can be used on any weapon without adjustments having to be made.

Aiming using a prefab at no angle works as intended Using the same sight at a different rotation causes misalignment

Originally I was going to do this by having the developer set the position of where they would like the sites to go, and then set the position based on the rotation of the weapon. This caused an issue later when I realised if the developer would like the site to be attached at an angle, the system would not support that. The solution to this was to set an attachment point for the site, using an empty game object, this will allow the developer to set the position and rotation a lot easier than having to figure out the correct position with trial and error.

Using the new system fixes issues with misalignment

Multiple Sights

After completing the aiming system I had some time left to take on another task, I decided to add the ability to have multiple sights on a weapon and switch between them. I did not have plans to add this in from the start, however, while I was testing the new aiming somebody suggested I add it. With the new aiming system it made this quite easy to accomplish so I decided to implement it.

Systems like this can be seen in Battlefield 4 (2013) with their canted iron sights, and Arma 3 (2013) with their 2 in 1 sights, aswell as other games. These are both different ideas but something that I would like to achieve with my system, this will allow the developers using my system to have the functionality they want.

Canted iron sight system in Battlefield 4 2 in 1 sight system in Arma 3

I started with the secondary sight system like the one in Battlefield this is an entirely separate sight mounted on a different point on the weapon. I started working on this by placing a second attachment point on the weapon, identical to the one I created for the core aiming, except it has a separate position and rotation. Using this point I set a key that would change between them so that the player can press a button and switch between sights.

Switching between sights when not aiming worked well with this method, however, if you tried to switch sights while aimed, nothing would happen, this is because of how I had built the system as I did not plan to have multiple sights implemented, this ended up being a silly mistake, I had to calculate the target position of the weapon before checking if the position of the weapon was the same as the target. After finding and fixing that, switching between 2 different sights worked.

Switching between 2 sights on 2 separate attachment points

Next I moved onto the 2 in 1 sights similar to Arma 3, after creating the secondary sight system, this was the functionality was already there, all I had to do was check if there was another sight attachment point on the weapon, if there isn't it will only switch the sight, and not the attachment point.

Switching between 2 sights on the same attachment point

After creating this, I realised that you cant have a 2 in 1 sight aswell as a secondary sight, which won't be a problem for the majority of people, however I want my system to be as modular as possible, and not giving them the option to have all of these is not ideal. To fix this I decided to change the way I save the different attachment points for aiming. Currently the developer puts has to set the attachment points in the unity inspector, aswell as the sights on those points.

The system can now switch between as many sights the developer would like

The way it works now is, each sight knows what attachment point it is connected to and instead of setting the current attachment point and current sight, the system now only knows the current sight, and when it needs the current attachment point, it will get it from the sight. The benefit of this is that I can now have just an array of sights, and switch between them, rather than having 2 preset attachment points and 2 preset sights. This has also cleaned up the code a lot, previously it took 6.

Old method of switching (Simplified for the blog) New method of switching (Simplified for blog)

This is everything I did for the past 9 days. It should have taken less time but I had other University modules that were taking up time. The next blog will be the work I do for the rest of this week. The work done in the past 4 and a half weeks has taken a lot less time than I had anticipated so all of the work I had planned to do has been completed, because of this, I have decided that the rest of this week will be dedicated to optimising the code I have already written, making sure it is all as readable as possible, and making sure that the modular components of the system are as intuitive as possible to ensure the usability of my system is as good as it can be.

Bibliography

Battlefield 4. 2013. PC [Game]. EA Dice

Arma 3. 2013. PC [Game]. Bohemia Interactive

Comments