Framework Retrospective (recap)
Objective: Cover some of what I did to upgrade from Legacy System to Unity’s New Input System.
For this modules Framework, I had to take an existing game and upgrade it to the new input system. I’ll cover how I handled it. We will start with the player movement. First thing to handle is setting up an Player Action Map with the bindings for keyboard, WASD & Arrow keys for a Vector2 direction and E for interacting with objects. I also added a Controller bindings. I did the similar thing for each object that would need it’s own Action map.
The Laptop just needed to swap camera’s by using the E key to switch and an exit key to get out of the Camera mode.
Drone needed a Vector 3 to be able to fly up and down and tilt left and right, A float value to be able to rotate, and to exit the drone mode.
And finally the Forklift needed a Vector 2 for movement, a float value to lift and lower the lift, and as the others a way to exit forklift mode.
Next was to create a GameInput class to take the input for the new input system and give it to the correct classes to use the input. Started by getting a reference to the player and the input actions.
Now it is time to Enable the Player Actions map. We created a method to Initialize the initialization of the new InputActions, and enabled the Player action map.
For Player, Drone, and Forklift movement we checked to see which is enable and created a local variable to hold the values from the input of Movement. We then passed in the local variable to a public method that each class has that we will look at in a few.
We also have a reference to each of them. As well as the laptop.
We will also create an event Action. This will let all the interaction scripts to listen for the input from the GameInput script instead of using an array and call it with a foreach loop.
We will also Subscribe to the Action map actions for all the Action maps needed.
Once we have subscribed we will invoke the onInteractionInput in the Player actions.
We will move to the player class. In there we create a public method to get the direction and pass it to a variable that can be read in the CalcutateMovement method.
Current it was to check for Input.GetAxisRaw on moth Horizontal and Vertical axis. After getting the direction we just remove the Input.GetAxisRaw for both h and v. We then pass in the movement.x and movement.y for the horizontal and vertical axis.
That’s the player movement. We will move on to the Interactions. We will open the InteractableZone and subscribe to the GameInput._onInteractionInput. We will also create a bool variable to see if we are or are not getting input. This helps with having to hold for an interaction.
Subscribing to an action will create a method. The new method will change the bool between true and false.
Now we just check to see if that input is true and complete task and if it’s not quit hold state.
Now we are able to interact with the intractable zones. Movement for the Drone and Forklift was the same. The Drone had a tilt feature that allowed the drone to tilt 30 degrees in all four directions. Easy way to handle this with the new input system was to limit scale processor.
For the Laptop, Drone, and Forklift we checked for the entering of each Action Map and Disable and enabled the appropriate Action Map.
This was a small recap of some of the things I had to fix for the new input system. Thank you for reading and have a wonderful day!