New Input System — 2D Vector Composite!

addam davis
3 min readDec 17, 2023

--

Objective: Create smooth movement using the New Input System!

In the previous tutorial we focused on calling methods for our actions. This tutorial we are going to create that functionality for our player. Specifically, for our player movement.

We have our Action Map for movement.

To begin we create a new script for our player and attach it to the player object.

Remember, we need to do three things. Initialize the ‘PlayerInputActions’, enable it, then do out preform registration for the event.

Next, we can run a debug log and get the actual vector value.

Start the editor and you can see the readouts in the Console view.

From here we could directly add our movement in the performed method. We only need a variable to hold the Vector 2 value and use a ‘transform translate method.’

This will work. Unfortunately, this method will only becalled once one of the ‘WASD’ keys are pressed.

We can easily fix this and give ourselves smoother movements with a minor adjustment to out code. We can remove the performed method and check.

We can poll, or check, our input reading in the update method.

Now we can redo our transform translate method.

Now in the editor our player will have buttery smooth movement.

This is all there is to it. If you wanted to change from moving up and down and instead move towards the camera and away, we could with a simple Vector3.

Now you know how to create movement using the New Input System. Don’t be afraid to experiment with your code and I’ll see you in the next tutorial!

--

--