2D Vector Composite w/ NUIS
Running and Walking with Values
So far we have the ability to perform an action using a single button press. This could be, as we have thus far, a bark action. It could also be used for firing a projectile as well.
Now let’s focus on getting our Dog to walk.
First, we will select the Dog from the Input Action Map(IAM) and then create a new Action called Walk.
For this example, under the Action Properties bay →Action →Action Type, we will select Value. When we select the Control Type dropdown we will see several options. We will choose a Vector2.
Next, we will add a new Up/Down/Left/Right Composite binding.
This will add a 2D Vector to our Dog’s Walk Action. Opening this up we will see options to bind keys to the Up, Down, Left & Right aspects of the 2D Vector.
To do so we will perform the following steps:
- Select the 2D Vector option you wish to assign a binding to. This will open a new bay titled Binding Properties.
- Under the Binding Properties bay we will select the Path dropdown.
- Press the listen button followed by the key you wish to bind the action to (UP → W).
- Perform this action for each of the 2D Vector options.
- When finished, save your Input Action Asset
Using A Script To Get Our Dog Walking
Now it is time to jump back into our script and hook up the walk action.
Since we already have a script up and running for our Dog we can skip right to registering the Dog’s Walk Action
Next we will alter the Walk_performed() function to read a value on each key press:
As we can see, the walk function is reading appropriately.
Notice that we have created a variable called move that accesses the values on the X axis as well as the Y axis, both of which correspond to the appropriate key presses(A & D on the X axis, W & S on the Y axis).
The same process may be applied to a Run action for the Dog as well.
Next, let’s look at swapping action maps in the next article: ‘How To Swap Action Maps In The NUIS’.