How to make 2d platformer in Unity?

Getting Started with 2D Platformer in Unity

Unity is a popular game engine that allows developers to create 2D and 3D games with ease. One of the most exciting features of Unity is its 2D game engine, which makes it an ideal choice for creating 2D platformers. In this article, we’ll guide you through the process of creating a basic 2D platformer in Unity.

Setting Up Your Project

Before we begin, make sure you have Unity installed on your computer and set up a new project. Here’s a step-by-step guide:

  • Create a new project: Go to File > New > 2D Project and choose the 2D template.
  • Choose a project name: Give your project a name and set the Scene name to something descriptive.
  • Set the game mode: Choose 2D or 3D to determine the game mode.

Setting Up the Canvas

The Canvas is the main component that contains all your game elements, including player, platforms, and obstacles. Here’s how to set up the Canvas:

  • Create a new Canvas: In the GameObject menu, select Create > 2D > Canvas.
  • Configure the Canvas: In the Canvas settings panel, set the Width and Height to 800 pixels.
  • Set the Canvas parent: Set the Canvas parent to GameObject.

Setting Up the Player

The Player is the main character that will be controlled by the player’s input. Here’s how to set up the Player:

  • Create a new Player: In the GameObject menu, select Create > 2D > Character.
  • Configure the Player: In the Player settings panel, set the Width and Height to 50 pixels.
  • Set the Player’s properties: Set the Player’s properties to:

    • agility: Set to 100 to make the player agile.
    • jump height: Set to 50 to make the player jump high.
    • gravity: Set to 9.8 to make the player fall downwards.
  • Set the Player’s movement: Set the Player’s movement to Transform and WindSpeed.

Setting Up the Platforms

The Platforms are the objects that the player will interact with. Here’s how to set up the Platforms:

  • Create a new Platform: In the GameObject menu, select Create > 2D > Platform.
  • Configure the Platform: In the Platform settings panel, set the Width and Height to 50 pixels.
  • Set the Platform’s properties: Set the Platform’s properties to:

    • Layer: Set to 2 to make the platform visible in the second layer.
    • Rigidity: Set to 1 to make the platform rigid.
    • Dynamic: Set to false to prevent the platform from moving.

Setting Up the Obstacles

The Obstacles are the objects that the player will need to avoid. Here’s how to set up the Obstacles:

  • Create a new Obstacle: In the GameObject menu, select Create > 2D > Object.
  • Configure the Obstacle: In the Obstacle settings panel, set the Width and Height to 50 pixels.
  • Set the Obstacle’s properties: Set the Obstacle’s properties to:

    • Layer: Set to 3 to make the obstacle visible in the third layer.
    • Rigidity: Set to 1 to make the obstacle rigid.
    • Dynamic: Set to false to prevent the obstacle from moving.

Setting Up the Physics

To make the game look realistic, you’ll need to set up the Physics system. Here’s how to set up the Physics:

  • Create a new Physics Body: In the GameObject menu, select Create > 2D > Physics Body.
  • Configure the Physics Body: In the Physics Body settings panel, set the Mass to 1000 to make the object weigh 1000 units.
  • Set the Physics Body’s properties: Set the Physics Body’s properties to:

    • Surface: Set to Wall to make the object collide with walls.
    • Sensor: Set to Wall to make the object collide with walls.
    • Trigger: Set to Wall to make the object collide with walls.

Creating the Player’s Movement

To make the player’s movement look smooth, you’ll need to create a Character Controller. Here’s how to create a Character Controller:

  • Create a new Character Controller: In the GameObject menu, select Create > 2D > Character Controller.
  • Configure the Character Controller: In the Character Controller settings panel, set the Speed to 100 to make the player move quickly.
  • Set the Character Controller’s properties: Set the Character Controller’s properties to:

    • Integration: Set to Precursor to make the object move with the scene.
    • Fixed rotation: Set to true to make the object move with the scene.

Creating the Platformer Mechanics

To make the game look realistic, you’ll need to create some platformer mechanics. Here’s how to create them:

  • Create a new MonoBehaviour: In the GameObject menu, select Create > 2D > MonoBehaviour.
  • Configure the MonoBehaviour: In the MonoBehaviour settings panel, set the Bounce property to true to make objects bounce off walls.
  • Set the MonoBehaviour’s properties: Set the MonoBehaviour’s properties to:

    • tick interval: Set to 30 to make the object tick every 30 milliseconds.
    • Fixed Timestep: Set to false to make the object tick every frame.

Creating the Obstacle Sprites

To make the obstacles look cute, you’ll need to create some obstacle sprites. Here’s how to create them:

  • Create a new Sprite: In the GameObject menu, select Create > 2D > Sprite.
  • Configure the Sprite: In the Sprite settings panel, set the Width and Height to 50 pixels.
  • Set the Sprite’s properties: Set the Sprite’s properties to:

    • Layer: Set to 4 to make the sprite visible in the fourth layer.
    • Rigidity: Set to 1 to make the sprite rigid.
    • Dynamic: Set to false to prevent the sprite from moving.

Creating the Platformer UI

To make the game look nice, you’ll need to create some UI elements. Here’s how to create them:

  • Create a new UI System: In the GameObject menu, select Create > 2D > UI System.
  • Configure the UI System: In the UI System settings panel, set the Component to Scroller to make the object move horizontally.
  • Set the UI System’s properties: Set the UI System’s properties to:

    • Size: Set to 200 to make the object move horizontally.
    • Speed: Set to 100 to make the object move at 100 pixels per second.

Tips and Tricks

Here are some additional tips and tricks to make your 2D platformer look nice:

  • Use sprites: Use sprites to make the game look cute and colorful.
  • Use UI elements: Use UI elements to make the game look nice and easy to use.
  • Use particle effects: Use particle effects to make the game look cool and dynamic.
  • Use animations: Use animations to make the game look smooth and realistic.

Conclusion

Creating a 2D platformer in Unity is a great way to start your game development journey. With these steps, you can create a simple 2D platformer that looks great and plays smoothly. Remember to use sprites, UI elements, and particle effects to make your game look nice and easy to use. Good luck and have fun!

Unlock the Future: Watch Our Essential Tech Videos!


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top