Reworking the 2.5D Side-scrolling Game

Objective: Recreating the character controller

Simon Truong
5 min readJan 31, 2024

--

Before we can import the Blender 3D assets into unity and start playing around with level design, we first need to create our player. Just like last time we are going to be using the New Unity Input System.

And just like last time we are going to basically start by downloading the Input System Asset from the Unity Package Manager. Once you do, Unity will show a pop up telling you that you will need to do a re-launch of the application so the input system can be incorporated into the core functions. If you are having issues with the New Input System, click here for an in depth tutorial on how to use it.

Installing the New Input System.

Once that is over with, within our Projects Tab, we are going to create an new Folder to house all of our Input data.

Then we are going to right click that folder and create an new Input Actions.

Give that new Input Actions a name, then double click the file to get to the Actions window. Once you are inside the this window, by default should have an Action Map created with Actions. We can delete this as we are going to be starting fresh.

Start by creating an Actions Map called Player. Then in the Actions, create one called “Movement”. All Actions now are going to belong to the player Action Map. If you require other types of players or vehicles, we will require more Action Maps.

For the Movement Actions Properties, since we this going to be an 2.5D game, we are only going to be limited to moving Left and Right. Therefore a Vector 2 is all you really need. Then for the Left and Right Actions, you are going to bind them to the A and D key.

Once that is all completed, remember to click the save button on the top. It is important to do this because all the changes done so far aren’t applied yet. There is that handy “Auto save” feature, but I personally find that it slows down the progress since it saves automatically for every little change. Finally before we can start scripting, we need to convert this Action Maps into an workable C# file. Select the Input Actions from the Project tabs, then in the Hierarchy tab, check the “Convert to C# script” check box. Unity will make a clone of the Action Maps and turn it into an readable script file.

Create an New C# script and name it something that can be easily identify as for player movement. I named my file “Player_Movement”, simple and easy to understand. Then, if you haven’t created an 3D capsule for a make shift player, we can do so now. Then attach the player movement script into this 3D object.

Open this script within Visual Studios and we can finally start scripting. To begin we are going to need access to the New Unity Input System library. So on the very top we are going to write:

using UnityEngine;
using UnityEngine.InputSystem;

Since this is the new Input System, we won’t have to worry about void Updates since all key presses will be done by listeners. First we are going to need access to the Action Maps. We are also going to add in a private float variable called “move Speed” which we can toggle how fast our player can move.

[SerializedField] private InputActions _inputActions;
[SerializedField] private float moveSpeed = 5f;

Then we are going to start with a “private void Initialized” method in which we will activate the Input Actions. Then we are going to Trigger it on the Start method.
Don’t forget to add an On Disable method to disable the Action Maps. Without this we will have some errors occur when play testing.

private void Initialized()
{
_inputActions = new InputActions();
_inputActions.Player.Enable();
}

private void OnDisable()
{
_inputActions.Player.Disable();
}

void Start()
{
Initialized();
}

Now to add in the “On Click” functions for the movement. So whenever we use the A or D key on our keyboard then we will trigger the corresponding Action on the Action Map. First we are going to create a new private method called “Regular Movement”. Within this method we are going write in all the character movement scripts. We are going to start by creating an local variable called “move”. In this local variable we are going to get the “Read Value” whenever the A or D has been pressed, then assign it to an vector 2.

[SerializedField] private InputActions _inputActions;

private void Initialized()
{
_inputActions = new InputActions();
_inputActions.Player.Enable();
}

private void OnDisable()
{
_inputActions.Player.Disable();
}

void Start()
{
Initialized();
}

private void RegularMovement()
{
var move = inputAction.Player.Movement.ReadValue<Vector2>();
}

Then we are going to basically do an Transform Translate whatever the value of “move” is multiplied by a speed variable and delta time.

private void RegularMovement()
{
var move = inputAction.Player.Movement.ReadValue<Vector2>();
transform.Translate(move * moveSpeed * Time.deltaTime);
}

Finally to make sure this private method is constantly being triggered, we will apply this method into the Update Method.

void Update()
{
RegularMovement();
}

Once we play the game, the player should be able to move left and right according to the proper key presses.

--

--

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.