2.5D Platformer — #2 Horizontal Movement

Objective: Non-physics Character movement using the Character Controller

Jean-Noel Seneque
4 min readOct 13, 2021

In the last article, 2.5D Platformer — #1 Greyboxing, we discussed the reasons for grey boxing a level and rapidly prototyping the core mechanics. In this article, we will develop the first core mechanic, character movement.

For this project, we are going to make use of the Character Controller so we have control of all the character's movements.

In the scene, I have a character placeholder for my capsule and interesting enough the Character Character’s collider is a capsule. This placeholder model will no doubt be swap out down the line. With that in mind, let’s create an empty game object named Player, reset its position to zeros and drag the capsule into it.

It is best practice to keep the logic and behaviour separate from the graphics/model. That way, when we do come to the time to swap out the capsule mesh for a proper 3D model, we can easily do this without having to copy and paste components, tweaking tags, layers, etc.

Let’s add a Character Controller to our player.

The Character Controller comes out of the box with a few properties I want to make you aware of. Here is the Unity documentation on the subject,

Slope Limit — this controls what angles below this number the character will climb.

Step offset — the step height from the ground the character will step up onto.

For our purposes, we do not need to modify any of these settings.

Let’s create a Player script and create a reference to the Character Controller component.

Next, we want to move based on the user input. I am going to set this up as if I am receiving input from either the keyboard or game controller. To achieve this, in the Update method, we use the Input.GetAxis on the Horizontal input. This is defined in the Input Manager Project Settings.

There are a couple of variables we need to move something, first is the speed and the Move method needs a Vector3 but we are only getting the horizontal values for now. Let’s define the direction and with speed and direction, we have velocity. I also set the speed to 6.

We have movement but you will notice the player reminds hover in mid-air. Let’s apply gravity.

We need a variable to define gravity, captures it as the y-direction but later we will work gravity and jumping against each other but at the moment gravity is the only force we care about.

As a result, you can see as soon as the game starts, the Player falls onto the platform.

That is it for this article. We have horizontal movement with gravity. In the next article, we will bring in jump and double jump.

If you enjoyed reading this article give me a Clap, also if you would like to see more, “Follow” me, so you may be notified of future releases. You may also send me a message if you need any further help.

Do you have a project in mind and need help getting it started, reach out to me

--

--

Jean-Noel Seneque

A Data & Analytics Consultant who is expanding into developing experiences in XR, Enterprise and Gaming space using Unity www.jeannoelseneque.com