Creating a 2.5D side scrolling Game
Now that we have a working prototype of the player, it is time to create collectable items that will be found within the future levels. Collecting items has always been the main focus on progressing game play, especially in 2D side scrolling games. Since we will be working with assets from the ground up, I decided to create my own personal drawings which will be used in the game.
Prototyping the collectables:
In Adobe Illustrator I started a new file which will be the file that will contain all of my sprites and assets that I will draw to be imported to the game later. Since the player is going to be in a shape of a orange tabby cat, I decided that the most fitting item to collect would be cat food, canned cat food to exact.
After some inspiration from google, I ended up with a drawing like this:
To quickly test this out, I exported this file as an PNG image and drag the file to Unity. There I converted the image file to an sprite (2D and UI) texture type. I kept the Sprite Mode to Single since it is only one object within this image. Then drag the image to the scene.
Once in the scene, I reduced the overall size (since it was slightly too big) to fit along the player and other environmental size. Since this is still a 2.5D game, and 2D images don’t cast shadows, I created an 3D cube as a child object. Then set the rendering to just cast shadows only, that way I have the luxury of creating an shadow without any box rendering.
To finish up the item we are going to add in a box collider (3D) and make sure that the “is Trigger” is checked. Then an Rigidbody(3D) and make sure that the “Use Gravity” has been unchecked.
Scripting the Collectable:
Create an new script called “Collectables” and drag it to the Tuna collectable inspector.
Then open the script in Visual Studios (or any other editing software). Since we are still in the prototyping stage, we are basically creating the function of the item disappearing once the player has made contact with the object.
To do this, we are basically going to use an On Trigger Enter and check whenever the player has made contact with the collider. If that is true we are going to destroy this item.
Save and return back to Unity.
Animating the Collectable:
To add just a bit more flare and also user feedback to indicated that these floating tuna cans are indeed collectables, we are going to add in a slight movement as animation.
To add the animation to the 2D sprite, we first need to reorganize our hierarchy. Since the animation involves movement, we can’t have the sprite game object as the parent. Otherwise whatever animation position we started with, will stay and will affect our future positioning. To solve this we are going to create an new empty game object and have the tuna can collectable, along with the shadow cube as child objects.
Then when creating a new animation sequence make sure you select the Tuna Collectable first!
For my quick animation, I just when with a floating up and down movement.
Once you are happy with the animation, we can drag the overall game object into the a folder in the projects tab so we can convert that into a prefab. This allows quicker applications in the future where you can duplicate them.