Journal 76 — Unity 2.5D Platformer Setup, Physics Based Character Controller

Objective: Develop a new 2.5D Platformer, first setup of character controller with jump and collectables

In this new series of articles, we are going to prepare a 2.5D platformer project consisting of a platform world with collectables, and a physics based character controller created from scratch.

Character Controller Movement

We can start with a basic setup of platforms, collectables, and a capsule to represent the player. The platforms and collectables can be converted to prefabs. Then we can add a Character Controller component to the player and start setting up basic C# scripts. Note the Character Controller already includes a collider so if you have a Capsule Collider, you can remove it.

Now we want to create a new C# script for the player and create horizontal movement. We can also add a speed component that is adjustable.

Jump

Let’s update the C# script with the ability to jump. While setting this up, we can create a couple variables to set the jump height and also the effect of gravity, and a double jump effect that we can check with a bool variable. All the variables for gravity, jump height, and speed can be adjusted to your preferences.

Here are the results.

Collectables

Let’s fix the collectables. On each collectable, add a Sphere Collider set to Trigger and a RigidBody component. We can create a UI text element that we can call “Coins” to show onscreen.

We will need a Coin script added to the collectables, and a UIManager added to the Canvas game object.

In the Coins script, we can add an OnTriggerEnter function to check if the Player picks up the coin. We will access a public method on the Player script to add coins.

On the Player script, we will have a new integer for the coins, a reference to the UIManager, and a public function to add the coins and send the number of coins to change the UI.

In the UIManager, we can get a reference to the coin text, and create a new public function to update the coin text.

Finally, here are the results.

Thank you for your time!