Final Project Week 15 - Bug Fixing and Input Manager
In my previous blog post, I finished all of the features that I planned to implement into my system. because of this, I took a break from this project for easter and to focus on my other university module. I did test my system over the break, in this blog post, I will be focusing mainly on fixing any issues that I found. I will also work on implementing some stretch goals that I wanted to implement if I had time.
Input Manager and Controller Support
The first stretch goal that I wanted to implement was an input manager that would make the system easier to set up with the keys the developer wants, I also used this time to ensure that my whole system is usable with a controller, in case the developer would like their game to be used on consoles.
Input Manager
Unity already has an input control built in, my manager is not made to replace it, but to allow the user to select the unity input that they would like to use, without having to give their inputs specific names, or go into the code and change it themselves, this just allows the developer to set up the system exactly how they would like.![]() |
Custom Inspector for the Input Manager |
Once the manager was complete, I wrote a custom inspector that limited what the developer could change. This is necessary because I want the system to be useable without touching the code. If the user has access to the names of the inputs in the input list, the scripts would throw errors because they wouldn't be able to find the inputs they need.
Controller Tweaks
With Unitys input system and my input manager in place, a lot of the weapon system was usable with a controller already, the items that needed changing are shooting, aiming and UI control.The reason the majority of the inputs already worked is because the input method on a controller is the same as a keyboard and mouse, for example, movement and mouse look already used axes, so remapping that to the sticks worked perfectly, other inputs such as jump, switch weapon and open editor, all used buttons on both keyboard and controller.
The reason aim and shoot do not work in the same way is that using a mouse, they use buttons, but on a controller, they use the triggers which are treated like axes. Fixing this was fairly simple, in the code, there is an if statement that will check if the button is pressed, in that if statement I added an or that checks if the aim/shoot axes are over 0, this means that it is pressed. This worked perfectly for the aiming but didn't work as intended for the shooting, this is because the shooting system that I have set up looks for when a mouse button is pressed, not held, but there is no built-in function to check if an axis has been pressed. This meant that on single and burst fire, the gun would shoot constantly while the trigger is held, without waiting for it to be released. To fix this issue I created a function that will check if the trigger was pulled in that frame, and will then wait for the user to release the trigger before allowing the weapon to shoot again.
![]() |
Code used to check if a trigger was pulled in this frame |
This can be called very quickly wherever needed now, allowing me to set up single and burst fire with a controller.
The GitHub repository for this project is available here: https://github.com/ElliotChester/Modular-Weapon-System-Final-Project
Comments
Post a Comment