Tuesday, March 31, 2020

Tutorial: How to Make a 2d Platformer in Unity - Tilemap Basics

Setting up the Sprite Sheet:

In the Project window, select ground.png from the pixel2dcastle1.1.zip.  Then, in the inspector change the Texture Type to Sprite (2D and UI), change Sprite Mode to Multiple, change the Pixels Per Unit to 16, and change the Filter Mode to Point.  Next, open the Sprite Editor window, click on Slice, change Type to Grid By Cell Size, change Pixel Size to 16x16, click the Slice button, and before you close the Sprite Editor window click Apply in upper right corner to save the changes.

Creating the Tile Palette:

First, create a folder where you would like to store your Tile Palette and click on Window>2D>Tile Palette.  In the Tile Palette Window, click on Create New Palette and save the palette in the folder you created.  Find the ground.png file in the project view and click the arrow next to it expand the sprite list.  Drag ground_1 and ground_17 into the Tile Palette Window and save the tiles to your folder.  

Creating the Tilemap:

Click on the menu option GameObject>2D Object>Tilemap to create a Tilemap in your scene.  Next, click on the arrow next to the Grid object in the Hierarchy view to expand it and click on the Tilemap object.  Open the Tile Palette window and click on the paint brush icon, select the tile you want to paint with.  Then, paint a row of tiles that we can move the player around on.  Finally, in the Inspector view with the tile map object selected click Add Component and add Tilemap Collider to the Tilemap object.

We're finally ready to start writing code.  In the next part we'll be animating our character implementing running and jumping.

Follow this link to the next post.

Monday, March 30, 2020

Tutorial: How to Make a 2d Platformer in Unity - Creating Animations

Creating Animations:

Before we get started programming movement, we need to create our character and our animations.  To create a sprite animation in Unity simply select the sprites in the project window and drag them into the scene.  Highlight the idle sprites (adventurer-idle-00, adventurer-idle-01, adventurer-idle-02) from the adventurer character we downloaded in the last post and drag them into the scene to create an Idle animation.

This will create a GameObject with a SpriteRenderer and an Animator.  The Animator an Idle animation that is set as the default state.  If you hit the play button you will see the character looping through the idle animation.  Do the same with running animation sprites (adventurer-run-00, adventurer-run-01, adventurer-run-02, adventurer-run-03, adventurer-run-04, adventurer-run-05) and the jumping animation sprites (adventurer-jump-00, adventurer-jump-01, adventurer-jump-02, adventurer-jump-03) and save the animations with a name you'll remember.

Setting Up The Animator:

Delete all but one of the SpriteRenderers.  Click on the SpriteRenderer in the scene view and make sure it has an Animator and AnimatorController(if not add an Animator component and right in project view>create>Animator Controller).  Then click on Window>Animation>Animator to bring up the Animator window.  You should see the Animator that is attached to the SpriteRenderer.  Delete all the Animator states.  On the left side of the window click on the parameters tab and click on the plus sign to create a new float.  Name the float Moving.  Right click in the Animator window and select Create State>From New Blend Tree.  Click on the Blend Tree and rename it Idle.  Double click on the blend tree to edit it.  In the inspector, make sure that the blend type is set to 1D and that the parameter is set to Moving.  Click on the plus sign and add 2 motion fields.  Then, click on the circle to show the available animations and choose the idle and running animation for the fields.  The idle animation field should have its threshold set to 0 and the running animation field should have its threshold set to 1.


With the animation set up we're ready to move on the next tutorial!  Next we need to create an environment that our the player can move around in.  We will need to slice a sprite sheet and create a tilemap.
Follow this link to the next post.

Sunday, March 29, 2020

Tutorial: How to Make a 2d Platformer in Unity - Overview

This is the first in a series of tutorials showing You how to create a 2d platformer in Unity using the Unity physics system.  Before I show you the code I want to point you to the assists I will be using and I want to provide an overview of the series.  Below you will find links to the other posts and links to the assets I will be using.

Overview:

1.  Getting Started.
6.  Parallax Background.
7.  Climbing Ladders and Double Jump.
8.  Grabbing and Climbing Ledges.
9.  Enemy AI.


Getting started:

First make sure you have Unity installed.  You can grab it here.  I will be using Unity 2019.2 but any version after 5 should work.

We also need to download the assets I will be using.  Download Adventurer-1.5.zip, pixel2dcastle1.1.zip, and Grassy_Mountains_Parallax_Background-vnitti.zip.

Create a new project and move the files into the asset folder and let's get started programming!
Follow this link to the next post.