2.5D Platformer: Lives System

FJ Hagen
2 min readJan 25, 2022

--

The basic framework of the 2.5D platformer is almost done. The only thing left is to add lives. Before that, though, the player needs a way to die. Currently, if the player falls off the platform, they fall forever. So there needs to be a way to return the player to the start. So, first, add a long trigger collider below the playing area.

Next, add some code to this collider object:

The setup is simple enough. When the player crosses the trigger, reset them to a spawn position set in the inspector. However, I needed to disable the character controller and re-enable it when I respawned. The reason is that the player falls so fast that the trigger won’t catch the player in time. Now, onto lives. Add a UI element for lives, similar to the one for coins.

I edited the Coins UI as well.

From there, the logic works similarly to collecting coins. Check if the player passes the trigger, get their player component,

Death.cs

deduct a life,

Player.cs

and update the UI.

UIManager.cs

Let’s see this in action.

Now, I have the basic framework of a 2.5D Platformer. Moving forward, I’ll move on to more advanced features of a platformer.

--

--