How to make a configurable camera with the new Unity Input System
The new Input System is a lot more complicated than the original one. This makes it harder to learn at first, but for a good cause – it is far more robust and when setup correctly, will take less work to use.
To get started, create an Input Controls asset by right clicking in your Project Hierarchy and go to:
There are four new terms that are important to know when configuring the input:
A very common example of an Action to a multiple Input Binding mapping is having a “Fire” action, which might be bound to a trigger for a gamepad and the right mouse button for keyboard/mouse setup.
Action Maps, Actions and Input Bindings each have their own set of properties. We’ll look at these more throughout the tutorial.
The input scheme is going to be designed for a keyboard / mouse device but could be easily extended to other inputs as well, if needed. In total, we’ll have one control scheme and action map, four actions and five input bindings. The setup will look like this:
While this may look like a lot, creating the layout is simple. With the PlayerInputMapping asset open, create a new Action Map:
We want to use a 2D Vector Composite binding node instead of the default one that was created. This tells the Input System to send a 2D Vector each time the W, S, A, or D keys are pushed.
Don’t worry if this doesn’t make sense right now. We’ll walk through the values that are being sent as we hook up the Actions to our camera.
Do the same thing for the Arrow keys. Add another 2D Vector Composite and name it Arrows. Set each mapping to their respective arrow key. Your map should now look like:
Now we just need to setup the remaining actions and bindings:
Next, we’ll setup the Camera_Rotate_Toggle action and binding:
Lastly, we’ll setup the Camera_Zoom action and binding:
Click Save Asset to save your changes. Your map should look like this: