Overview

This tutorial covers the fundamentals of creating a 2D player GameObject for platforming. You'll learn how to set up a Player controlled by the user that fits a 2D Platformer setting.

This Player allows basic right-left movement and jumping, as well as a collisions setup.

<aside> ⚠️

This tutorial uses the new Input System package. It is already installed in the URP 2D template. However, you can check on it in the Package Manager Window.

image.png

image.png

Select de Unity Registry category on the left side and type Input System in the search bar*.*

image.png

If it is not installed, the Install button should be displayed instead.

</aside>


Deep-diving & How To…?

The Player Controller

Any game needs some way to make the user interaction come true on the screen. Let’s introduce the Player Controller.

In these tutorials, the Player Controller can be defined as the entity that handles the user’s interaction and how it interferes with the game. The essential example is the player movement, and involves input hardware such as a keyboard or a mouse.

In Unity, the latest way to do handle with this is though the Input System. However, we should prepare our Player Object first.

Player Object Setup - Visuals

Most of the time, the user’s interaction is related to moving around things they can see on screen. In Unity you just need a GameObject and a Script to make it happen, as well as some visuals.

Let’s create a Player object with horizontal (left-right) movement by placing a new GameObject with a Rigidbody 2D component. It can be done as shown in the picture below:

A Dynamic Sprite is a GameObject containing a Sprite Renderer and a Rigidbody 2D components.

A Dynamic Sprite is a GameObject containing a Sprite Renderer and a Rigidbody 2D components.

A white circle should appear in the scene. Reaname it as Player.

image.png

image.png

<aside> 💡

If you cannot see the object in the Game window, make sure that has a position close enough to your view.

In this case, the new GameObject is almost located at the centre of the world, witch now is the same the centre of the screen as well.

In this case, the new GameObject is almost located at the centre of the world, witch now is the same the centre of the screen as well.

</aside>

For our player, we’ll be using another asset from this website: