From 3D Prototype to 2D Assets, Part 3 — Pesky Bugs
What’s life without a little challenge on your sanity?
Bugs will do that to you.
In this section we’ll clear up all our little bugs and get our game looking, and reacting, fantastically!
Here’s where we left off:
I can see 3 problems so far.
- Our player and other Sprites are BEHIND the background.
- Our lasers are passing through our enemies
- and our player is passing through the enemies.
Fixing the sprites BEHIND the background
This is pretty easy to overlook, especially if you are new to 2D workflow. 2D sprites are written/rendered on Sorting Layers, and their Order in that layer.
Like layers of a cake, the icing is seen before the actually cake — the higher layer is seen first, and the higher number order is seen first in that layer.
To solve this we’ll create 2 sorting layers; a background and foreground:
Now everything floats above the background! But nothing interacts with each other :(
Fixing the Player, Laser, and Enemy collisions
When something is passing through another object, this is usually an indication of faulty collision detection. And for us, this is the case — our code needs to be revamped for 2D!
First though, we’ll double check that our Tags are still intact, because they are essential to our Collision detection method:
Next we’ll jump into our enemy code.
Previously, with our Collision detection, we were using OnTriggerEnter. But this is now incorrect. We are using a 2D trigger, so we must change our code to resemble that to OnTriggerEnter2D, and Collider2D:
If all went swimmingly, we now have a working game again! Now we can continue implementing features, in the 2d Realm!
Next we’ll be working on creating some PowerUps to make the game a little more interesting!