Lesson 6: 2D Game Development - Sprites, Animation, and 2D Physics
You have been working in 3D so far. Unity can also target 2D games: side-scrollers, top-down, puzzle games, and more. In this lesson you will create a 2D project (or switch an existing one to 2D), import sprites, set up the 2D renderer, build sprite animations, and use Rigidbody2D and Collider2D so your game feels like a proper 2D experience.
By the end of this lesson you will:
- Create or configure a 2D project and understand the 2D/3D mode toggle.
- Import sprites and use Sprite Renderer and Sprite Editor (slicing, pivots).
- Create sprite sheet animations with the Animation window and Animator.
- Use Rigidbody2D and Collider2D (and 2D physics materials) for movement and collision.
- Know when to use 2D vs 3D physics and rendering so your project stays consistent.
1. 2D vs 3D in Unity
Unity can mix 2D and 3D in one project, but for clarity and performance it is better to choose a primary mode:
- 2D ā Camera is orthographic, sprites are drawn with the 2D renderer (URP 2D or Built-in 2D). Physics use Rigidbody2D and Collider2D. Great for side-scrollers, top-down, puzzle, and mobile 2D games.
- 3D ā Camera is perspective (or orthographic), 3D meshes and lighting. Physics use Rigidbody and Collider. What you used in Lessons 1ā5.
Creating a 2D project: When you create a new project, choose the 2D template. That sets the default renderer to 2D and the scene view to 2D mode. If you started in 3D, you can still add 2D content: add a Sprite Renderer, use a Pixel Perfect Camera or orthographic camera, and use Rigidbody2D and Collider2D for 2D objects. Do not mix 2D and 3D physics on the same objects.
2. Importing Sprites
Supported formats: PNG, PSD, and other image formats. PNG with transparency is common for characters and tiles.
Import settings:
- Select the image in the Project window.
- In the Inspector, set Texture Type to Sprite (2D and UI).
- Set Sprite Mode ā Single for one image per file, Multiple for sprite sheets (one texture, many sprites).
- For sprite sheets, click Sprite Editor and Slice (e.g. by grid or automatic) to define each sprite. Apply and save.
- Set Pixels Per Unit (PPU) to match your art (e.g. 16, 32, 100). This defines how many pixels equal one Unity unit; keep it consistent across assets.
- Set Filter Mode to Point (no filter) for pixel art, or Bilinear for smooth art.
Pro tip: Use Sprite Mode: Multiple and slice once; then reference the generated sprites in your animations and prefabs. That keeps one texture in memory and simplifies batching.
3. Sprite Renderer and Scene Setup
- Add a Sprite Renderer component to a GameObject (or create 2D Object > Sprites > Sprite and assign your sprite in the Sprite field).
- Sorting Layer and Order in Layer control draw order (higher order in layer draws on top). Use sorting layers for "Background", "Player", "Enemies", "UI", etc.
- Color and Flip (X/Y) are useful for variants and facing direction.
- For pixel art, add a Pixel Perfect Camera component to the main camera (requires the 2D Pixel Perfect package) so pixels stay crisp when scaling.
Scene view: Use the 2D toggle in the Scene view toolbar so the scene is shown in orthographic 2D. That makes placement and layout much easier.
4. Sprite Animation (Animation Window + Animator)
To animate a character or object with a sprite sheet:
- Slice the sheet (Sprite Editor) so each frame is a separate sprite.
- Select the GameObject with the Sprite Renderer.
- Open Window > Animation > Animation. Create a new Animation clip (e.g. "PlayerIdle").
- In the Animation window, add a Property ā under Sprite Renderer choose Sprite. Click the record button and keyframe different sprites at different times (e.g. one sprite per 0.1 s for 4 frames).
- Create more clips if needed (e.g. "PlayerRun", "PlayerJump").
- An Animator component is added automatically with an Animator Controller. Open the controller (Window > Animation > Animator) and add your clips, then add Transitions (e.g. Idle to Run when a "Speed" parameter is greater than 0). Use Parameters (Float, Bool, Int, Trigger) to drive transitions from script with
Animator.SetFloat,SetBool, orSetTrigger.
Pro tip: Keep frame count and frame rate modest (e.g. 4ā8 frames at 8ā12 FPS for idle/run) so animations stay readable and performance stays good. Increase only where the player looks most (e.g. main character).
5. 2D Physics ā Rigidbody2D and Collider2D
2D games use a separate physics system so that movement and collision stay in the XY plane.
- Rigidbody2D ā Same idea as Rigidbody: mass, gravity scale, forces. Use Body Type: Dynamic for characters and moving objects, Kinematic for moving platforms (you move them in code), Static for immovable colliders.
- Collider2D ā BoxCollider2D, CircleCollider2D, CapsuleCollider2D, PolygonCollider2D, etc. One or both of the colliding objects must have a Rigidbody2D for a response. Use Composite Collider 2D to combine several colliders into one for performance.
- Physics Material 2D ā For friction and bounciness in 2D. Assign in the Collider2Dās Material slot.
- Collision/Trigger callbacks ā Use OnCollisionEnter2D, OnTriggerEnter2D, etc. (with Collision2D or Collider2D), not the 3D versions. Do not mix 2D and 3D physics on the same GameObject.
Moving the player: Either set Rigidbody2D.velocity in FixedUpdate (recommended for physics-driven movement) or use Rigidbody2D.MovePosition for kinematic-style movement. Avoid moving 2D physics objects by changing Transform.position every frame; it can fight the physics engine and cause jitter or tunneling.
6. Common Issues and Fixes
Sprites look blurry ā Use Point filter for pixel art and consider Pixel Perfect Camera. Check that PPU and camera size match your intended pixel density.
Wrong draw order ā Adjust Sorting Layer and Order in Layer on the Sprite Renderer. Ensure the camera is orthographic and not culling 2D layers.
No collision in 2D ā Confirm both objects have a Collider2D and at least one has a Rigidbody2D. Check the Layer Collision Matrix (Edit > Project Settings > Physics 2D) so the two layers can collide.
Animation not playing ā Ensure the Animator Controller is assigned to the Animator component and that a default state is set. Call SetFloat/ SetBool/ SetTrigger from script so transitions fire.
Summary
You learned how to set up 2D in Unity: import sprites (single and sprite sheets), use Sprite Renderer and sorting, and build sprite animations with the Animation window and Animator. You also used Rigidbody2D and Collider2D for 2D physics and saw how to avoid mixing 2D and 3D systems. In the next lesson you will go deeper into 3D Game Development ā models, materials, and 3D physics ā so you can switch between 2D and 3D projects with confidence.