From Prototype To Work of Art

Austin Hall
4 min readSep 27, 2022

--

Taking your project from primitive objects to something that looks like a real game, might seem like a daunting task. Just take it one step at a time.

First, lets look at the Player. As you can see, we have a cube mesh filter, a Mesh Renderer, a Box Collider, our script, and a 3D rigid body(not shown).

What we want to do is convert this 3D object over to one of our sprites (2D assets). We have already downloaded the asset packages we will be using for this game. you can see some extra folders in the assets tab, one of which, is labeled sprites.

New Asset Packages for Audio and Sprites

We want to select the player turn left sprite folder, and drag the Player Turn Left0000 sprite into the Hierarchy.

The sprite object is a 2D object. It will initially have a Transform and Sprite renderer component. Lets rename it to Player. and we can then delete the primitive 3D cube player object.

Like the 3D objects, if we want collisions to work we need the correct components. So lets add a Box Collider 2D this time, because we are now converting the game to its final form. Check the box for ‘Is Trigger’.

Player Script on New 2D Player Object

Drag the Player script onto the object in the Hierarchy tab, and don’t forget to add the tag. For the enemy and the laser, we will follow the same process but with an added step. We also need to add a Rigid Body 2D component to each of these objects. On the rigid body components, be sure the gravity scale is set to zero.

Box Collider 2D and Rigid Body 2D components

In the Sprite Renderer component, be sure that the reference is correct. If it is not, or is not present, simply drag the reference from the sprites folder to the reference box as shown below.

Adding Correct Reference to Sprite Renderer

If we were to run our game now we might expect it to work perfectly with our new graphics. You will be disappointed if you click play now. Nothing will function properly. Why? Well… when we started this project we used 3D objects and a 3D editor. All of our code was also written for 3D objects. now that we have converted our game to 2D, we need to adjust our code for the same.

Enemy Script, Changing Collisions for 2D Objects.

In our Enemy script, we navigate to our OnTriggerEnter() method. We can recall from the Unity API that this method is for 3D objects only. To use trigger collisions for 2D objects we need to use OnTriggerEnter2D(). We also need to change what we pass into the method from Collider to Collider2D. Now our collisions between the player and the enemy, and the laser and the enemy will function correctly.

All we have left is to adjust the scale of our new objects, the offset of the laser, and the boundaries for the collisions.

Adjusting Object Scale Using Rect Tool or Transform Component

To adjust the scale of the Player, we have two options. With the Player object selected, we can use the Rect Tool to manually adjust the size in the Scene tab. Or, we can go to the transform component in the inspector and set the X, Y, Z axis to a specific value.

Adjusting the Collision Boundaries

To adjust the boundaries for collision, select your desired object. In the Box Collider 2D component there is a small box labeled Edit Collider.

--

--

No responses yet