Devlog #6 - Wheels, Wheels, Wheels!


Hi and Hello! Code gremlin here to talk about one of the nice new things I have created, the weapon wheel! [or in our case the Gadget and Gizmo wheels?].

This was a feature that we knew we would want to have from the get go. There was a lot of discussion as to how it would work and what way we wanted it to be formatted. To be completely honest, I didn't think what we wanted in the end would be something that I could do. The issue with the traditional weapon wheel and what we wanted, was that ours needs to scale with the abilities you receive.  This would mean that we would have edit sprites and unity's built in button components to change procedurally. 

So how did it get done?

Unity's UI Image components have a nice value called "Image Type" where you can change your sprite to be "Filled". This means that you can set a value between 0 and 1 to basically mask off part of the image. This meant we could just create a wheel sprite and use the Radial 360 fill type to give us those procedural sprites we wanted. Our issue arises with the Button component in Unity. This uses the original sprite as the target graphic and not the masked sprite, so every button was triggering when you should only be hovering on one of them. I spent some time trying to get it to work, and there are some things you can do in code to ignore certain parts of the image with transparency, but this still wasn't working the way we needed it to. 


For a while I just focused on getting the buttons to spawn into their correct segments. This involved a nice amount of vector math and trigonometry to get the correct rotations and fill amounts for the wheel segments to look right. The code basically checked how many segments it needs to spawn and divide a circle up to get the angles. I had to write a Map function to get the angle in a range between 0 and 1 instead of 0 and 360 so it would work with the fill amount. This basically allowed me to spawn in the segments procedurally, the way I needed them to be. Unfortunately the actual button issue was still a thing.


To resolve the button issue I basically had to write my own code to act as the button script. The main concept is that it gets a vector of the direction from the center of the wheel to the players mouse. It then uses this direction and gets the angle created between it and the top of the wheel [with some more math magic to get the right angle in eulers and what not]. It then just uses similar code as the spawning of the segments, to find out how many segments your mouse is around the wheel, saves the index of that segment and gets the button at this segment from a list. There is some more stuff in there for knowing if we are on the left or right circle and all that, but that is the general idea of the whole thing.


There is some tweaking to do now in terms of getting it to work completely with a controller. The idea is that the left and right joystick control the left and right weapon wheels and you press a button to select which segment you are pointing to. 

The following video is a quick explanation of the code, and is a little easier to digest than all of this text! 

As always make sure to follow us here on itch.io for your weekly devlogs and maybe a few cheeky test releases, and follow us on Twitter for some more regular updates from the team!

cám ơn and thank you,

Round Table Studios.

Leave a comment

Log in with itch.io to leave a comment.