Unity Dev: 3D to 2D conversion

Alex Somerville
3 min readMar 25, 2021

--

We’ve got our cubes flying around in space and some little 3D capsule lasers. There’s enemies, there’s shooting, there’s lives, and there’s a nice little space background to cruise around in. Since we’ve already played around with adding Sprites in, we’ll continue on in a similar vein by using some graphics provided by our good friends at GameDevHQ.

Since we’re going to be using Sprites, we want to go through the process of converting our Game Objects to 2D. We’ll cover the bases of our Enemy object for this conversion and then the same principles can be applied to the Player and Laser prefabs.

Component Conversion:
Unity has unique 2D variations for some components which we’ll need to replace the 3D version with. First, let’s remove a couple unneeded components.

  • Cube (Mesh Filter)
  • Mesh Renderer

Now for the component variations:

  • Rigidbody > Rigidbody 2D
    You’ll want to turn Gravity Scale to 0.
  • Box Collider > Box Collider 2D
    Be sure to check off “Is Trigger”.

Because we’re now using a Box Collider 2D, we need to make a small revision to our Enemy.cs code. Put simply, we’re going to add “2D” to the end of OnTriggerEnter and Collider , like so.

Sprite Rendering:
Since I want to be able to rotate my sprite without affecting the orientation of the Game Object itself which could lead to my Player movement mechanisms getting wonked extremely out of whack, if you catch my drift.

Open your Enemy prefab (by double-clicking it in the Project window) and drag your base enemy sprite onto the Enemy game object. Rename this childed object as “Enemy_Sprite” and zero out the object’s position. Resize as desired and use the Box Collider 2D component on the parent object to draw an appropriately size Box Collider around the sprite.

Once you’ve applied these concepts to your Player and Laser objects, you should have a beautiful, never ending space shooter that works exactly like it did but now your friend cubes are gone. Which is sad.

Note: When working with Sprite Renderer components, you’ll need to tweak their Sorting Layers to ensure any given sprite is rendering in the right “place”, so to speak.

Use the Sorting Layer drop-down to add “Background” and “Foreground” layers. Keep in mind that the LAST one in the list will come FIRST.

Enjoy your very one-sided laser fight!

--

--

Alex Somerville
Alex Somerville

Written by Alex Somerville

On a quest to become a game developer. Still sometimes providing unsolicited advice about how to function in society.

No responses yet