Building a 2D Platformer in Unity
Thu Feb 19 2026
Why 2D Platformers Are the Perfect First Game
If you want to learn game development, there is no better starting point than a 2D platformer.
Platformers are:
- Easy to understand
- Focused on core mechanics
- Perfect for learning physics
- Ideal for building confidence
Games like Super Mario, Celeste, and Hollow Knight may look polished, but their foundations are built on simple mechanics:
Move. Jump. Land. Repeat.
By building a 2D platformer in Unity, you learn the most important fundamentals of game development:
- Player input
- Physics systems
- Collision detection
- Animation systems
- Level design
- Game loops
Let’s build one from scratch.
Step 1: Setting Up Your Unity Project
Start by installing Unity Hub and creating a new project using the 2D Core template.
Recommended Settings
- Template: 2D Core
- Renderer: Universal Render Pipeline optional
- Resolution: 1920x1080 (landscape)
- Target platform: PC or Android
After opening your project:
- Save your first scene as
Level01 - Create folders:
- Scripts
- Sprites
- Prefabs
- Animations
- Audio
Good folder structure keeps your project organized as it grows.
Step 2: Creating the Player
Now we create the core of your game — the Player.
Create the Player Object
- Right click → Create → Sprite → Square
- Rename it to
Player - Add components:
- Rigidbody2D
- BoxCollider2D
Rigidbody Settings
- Gravity Scale: 3
- Freeze Z rotation: Enabled
- Collision Detection: Continuous
Now let’s add movement.
Step 3: Writing the Movement Script
Create a new C# script called PlayerMovement.
Here is the core movement logic:
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 5f;
public float jumpForce = 7f;
private Rigidbody2D rb;
private bool isGrounded;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
float moveInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveInput * moveSpeed, rb.velocity.y);
if (Input.GetButtonDown("Jump") && isGrounded)
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Ground"))
{
isGrounded = true;
}
}
void OnCollisionExit2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Ground"))
{
isGrounded = false;
}
}
}
Attach this script to the Player object.
Press Play.
You now have movement and jumping.
Step 4: Creating the Ground
Create another sprite square and stretch it horizontally.
- Rename to Ground
- Add BoxCollider2D
- Tag it as Ground
Now your player can land safely.
Step 5: Improving Jump Feel
Great platformers are not about graphics. They are about feel.
To improve jump feel:
- Increase gravity slightly
- Add jump buffering
- Add coyote time
Example Coyote Time Concept
Allow jump for a short moment after leaving ground.
Add:
private float coyoteTime = 0.2f;
private float coyoteCounter;
Then adjust logic accordingly.
Small changes make your game feel professional.
Step 6: Adding a Camera Follow System
A static camera is boring.
Create a script called CameraFollow.
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform target;
public float smoothSpeed = 0.125f;
void LateUpdate()
{
Vector3 desiredPosition = new Vector3(target.position.x, target.position.y, -10f);
transform.position = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
}
}
Attach to Main Camera and drag Player into target.
Now the camera smoothly follows your character.
Step 7: Adding Animations
Animations bring life to your game.
Create Animation States
- Idle
- Run
- Jump
-
Open Animator window
-
Create Animator Controller
-
Add parameters:
-
Speed (float)
-
IsJumping (bool)
-
Update movement script:
Animator animator;
void Start()
{
rb = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
}
void Update()
{
float moveInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveInput * moveSpeed, rb.velocity.y);
animator.SetFloat("Speed", Mathf.Abs(moveInput));
animator.SetBool("IsJumping", !isGrounded);
}
Now your character visually reacts to movement.
Step 8: Creating an Enemy
Let’s create a simple patrol enemy.
- Create a new sprite
- Add Rigidbody2D
- Add BoxCollider2D
Create script EnemyPatrol.
using UnityEngine;
public class EnemyPatrol : MonoBehaviour
{
public float speed = 2f;
private bool movingRight = true;
void Update()
{
transform.Translate(Vector2.right * speed * Time.deltaTime);
if (transform.position.x > 3f)
movingRight = false;
if (transform.position.x < -3f)
movingRight = true;
if (!movingRight)
transform.Translate(Vector2.left * speed * Time.deltaTime);
}
}
Now your world has danger.
Step 9: Adding Health and Damage
Create a simple health system.
public int health = 3;
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Enemy"))
{
health--;
if (health <= 0)
{
Destroy(gameObject);
}
}
}
This teaches:
- Game state
- Player consequences
- Failure conditions
Step 10: Level Design Basics
Good level design teaches the player naturally.
Start simple:
- Safe jump
- Moving platform
- Enemy introduction
- Harder jump
Principles
- Teach one mechanic at a time
- Increase difficulty gradually
- Reward exploration
Platformers are about rhythm and flow.
Step 11: Adding Collectibles
Create coins:
Add CircleCollider2D
Set as Trigger
Script:
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Coin"))
{
Destroy(collision.gameObject);
}
}
Add score UI later for polish.
Step 12: Adding Sound Effects
Sound makes your game feel alive.
Add:
-
Jump sound
-
Coin pickup sound
-
Hit sound
Use AudioSource component and trigger it via script.
Even basic sounds dramatically improve experience.
Step 13: Polishing Your Game
Polish includes:
-
Particle effects
-
Screen shake
-
Better sprites
-
UI score display
-
Pause menu
Small polish elements separate prototypes from playable games.
Common Beginner Mistakes
- Overcomplicating physics
- Writing messy scripts
- Ignoring folder structure
- Skipping polish
- Not testing enough
Start simple. Improve gradually.
Expanding Your Platformer Further
Once the base works, try:
- Double jump
- Wall jump
- Dash ability
- Boss fight
- Save system
- Main menu
- Multiple levels
Every addition builds your confidence.
Why 2D Platformers Are Still Relevant in 2026
Indie hits continue to prove that 2D games thrive because they:
-
Are cheaper to produce
-
Focus on gameplay over graphics
-
Allow small teams to succeed
-
Scale well to mobile and PC
Mastering 2D platformers gives you the skillset to build commercial indie titles.
Apptastic Insight
Your first game does not need to be revolutionary.
It needs to be finished.
A small, polished 2D platformer teaches more than ten unfinished prototypes. Focus on movement feel, clean code, and gradual improvements.
Build. Test. Improve. Repeat.
That is how real game developers are made.
Thu Feb 19 2026
