Objective: Use the Movement action to move the player around.
In the last article, we got the dog to bark and the bark showed inside Unity Console. Today we will cover how to get 2D Vector Composite to move the character around. To start we will need to have the action map set up correctly.
We set this up in a earlier article:
Now that we have this done, we will move into the player script to start. As always working with Unity’s new input system, we need to use the Input library.
If we just tried to use the Action event it wouldn’t move as we want. To move we will need to read the value of the action.
We will use var to set the variable type and assign it a new Vector2. For the X and Y axis we will call it as _input.Dog.Movement.ReadValue<>(Vector2).x. Same goes for the Y.
The ReadValue will take in a type that could be in the Action value type.
All that is left is to use transform.translate(movement * a speed amount * Time.deltaTime);
With that we can move the character with the new Input System.
If we want to move in a 3D space using the Z axis as well, all we do is change the Vector 2 to Vector3 and move the Y to the Z axis location and that is it.
Thank you for reading and have a wonderful day!