You’ve probably played around with some of the action types and control types already. In this article I want to demystify the Axis Control Type.
I see a lot of stuff online where folks are trying to use ReadValue<> and look for a Vector2 type when they use a 1D Axis binding on their input action. In this example I’ll cover how to simply rotate an object while using the 1D Axis implementation.
First create the action map and set up the key bindings. I want the Action type to be a Value and the control type to be Axis.
Selecting the drop down to create a binding will now display the “Add positive/negative binding” option. This creates the 1D Axis. The composite shows a min value of -1 and a max of 1. I’ll leave all this as it is. I have 2 1D Axis bindings. One for A and D and one for left arrow and right arrow.
Now in the code, I want to Debug.Log the Axis Value. This is where I see lots of confusion. The 1D Axis binding is looking for a float value not a Vector2.
As you can see, running the game will display 0 until I press left or right. A = -1 and D = 1.
So now I can use this information to actually rotate an object.
There is an interesting behavior taking place right now. When I press A the cube rotates to the right. When I press D it goes left. This is inverted from what I intially wanted, so this brings me to Processors.
On the bindings, there is a handy option called Invert in the processors section.
Now when I run the game, the cube rotates in the “correct” direction. This kind of thing opens up lots of possibilities for different controls for the same functionality. For example, I could have A and D rotate it normally, but pressing Left arrow and right arrow could do the opposite. Why? Who knows! The possibilities are endless. I really like how this input system allows for more creative decisions and less debugging.