
Turret Controller
A system for adding controllable turrets to any game.
The goal for this project was to make a single versatile system that could be imported into any project and immediately work. It also had to follow consistent code standards and be easily understood by any developer that uses it.
Additionally, I modelled both cannons provided as examples.

This involved ensuring that my one-script solution was fully commented, and within its own namespace to prevent the CannonController class from interfering with a user's existing project.
I also made sure that all of the fields visible in the editor had tooltips that explicitly explained what they are. This way, a programmer can read them in-code as comments, but also the user can view the explanations as conveniently as possible.

The hardest challenge with this project was clamping rotations in Unity.
transform.rotation in Unity represents an angle between 0 to 360 degrees, while the editor displays angles as -180 to 180 degrees.
As the user can pick their own angles to clamp to, I figured that they would rather use the angles displayed in the editor - it is much simpler for a user to do so.
However, trying to clamp an angle between 0 and 360 degrees using clamps between -180 and 180 resulted in gimbal locking.
Rather than relying on transform.rotation, I created a separate tracking variable (m_VerticalRotation) to compare and clamp the rotations in the same format.
This added the change in rotation, the same way it would to the object's rotation, and if the value was over 180, it would force it to loop back around to the equivalent negative value.
This approach resulted in smoother turret behaviour and a simpler experience for the user.