Make A 2D Game With Unity3D Using Only Free Tools Part 3

Posted October 17th, 2011 in Tutorials, Unity3D, iDevBlogADay by Tim Miller

Welcome to Part 3 in this series on making a 2D sprite-based game with Unity 3D. In Part 1 I introduced you to the tools we’ll be using to make a Lode Runner style action game and in Part 2 we created the level sprites and built our first level. In this tutorial we’re going to be adding in the player, hooking up the scripts and adding collision to the ladders and ropes so that you’ll finally be able to run the character around in your levels.

This tutorial assumes that you have already followed along with Part 2 of this series so your project should be ready to continue on with the steps below. If you haven’t already done Part 2, you should go back and do that first so you can get a full understanding of how everything fits together. If you’d rather skip ahead, you can download the project up to this point. You can also click here to see how the game will look at the end of Part 3.

Making the Player Sprite Atlas

If you’ve been following the series, I know you’re excited to get the player character running around in the game, so the first thing we need to do is create a sprite atlas in TexturePacker.

  • Download the source sprite .png’s and unzip the file somewhere on your hard drive. If you already downloaded the sprites and added them to your project in Part 2, then you can skip this step.
  • Launch TexturePacker and then drag & drop all of the .png files from the sprites/player folder into the Sprites panel.

Texture Settings / Layout:

  • Set Algorithm to Basic
  • Set Border Padding to 1
  • Set Shape Padding to 1
  • Uncheck Trim

Texture Settings / Output:

  • Leave the Data format set to cocos2d.
  • Under Data File, click the little “…” button and browse to the location in your project’s Asset folder where you want to store your sprites (I put mine in Assets/SpriteAtlases), name the file “player” and then click Save.
  • TexturePacker automatically adds the .plist extension to the Data File, but Unity wants the file to be .xml. So in the text field, replace .plist with .xml.
  • The Texture File path should already be set to the same location as the .xml file except that it will have a .png extension so there’s nothing to do there.

If you followed the steps above, then your settings in TexturePacker should look like this (click the image to see a larger version):

Now if you click the Publish icon in TexturePacker and then switch back to Unity, you should see a player.png file and a player.xml file in the SpriteAtlases folder in the Project view.

If you don’t already have the project open in Unity, open it now and then load the scene that you created in Part 2 (eg. level1.scene).

We need to make a couple of changes to the sprite atlas in Unity so that it looks correct.

  • Select the player.png file in the Project tab. In the Inspector change the Filter Mode to Point.
  • Click the Override for Web box, set the Format to Truecolor and then click Apply.

Making the Player Sprite

Now we’re ready to turn the player’s sprite atlas into animated sprites using the Orthello 2D plugin.

The Sprite Container:

  • In the Unity Project tab, expand the Orthello folders: Orthello –> Objects –> Sprites –> SpriteAtlas and then drag the SpriteAtlas-Cocos2D object into the Hierarchy.
  • In the Hierarchy tab, expand the OT object and then the Containers object and you will see your new container with a name something like “Container (id=-6840)“. This is the Container that will hold all of our player sprites from the atlas we made so you can rename the Container to something obvious like “player“.
  • Drag the player.png from the SpriteAtlases folder and drop it on the “OTSprite Atlas Cocos 2D” script’s Texture slot.
  • Drag the player.xml from the Project, SpriteAtlases folder and drop it on to the Atlas Data File slot. Now if you drop down the little Atlas Data arrow, you should see that it’s populated with all the sprite atlas data that TexturePacker generated for us.

Setting Up The Player Animations:

Now we need to assign all of the frames from the sprite atlas to individual animations.

  • Drag an Animation object from Orthello –> Objects –> Sprites into the Hierarchy. This will add a new object under OT –> Animations named something like “Animation (id=-4320)“. Rename this object to “player anims“.
  • With the new “player anims” OTAnimation still selected, adjust the settings to match those in the following image. To populate the Container field, drag & drop the “player” object from OT –> Containers on to the Container field.

Click the image to see all of the animation settings:

Making The Player Sprite

  • Next find the AnimatingSprite object in Orthello –> Objects –> Sprites object in the Project tab and drag it into the Hierarchy, this will make a new object in the scene with a name like “Animating Sprite (id=-23050)“. Rename this object “player“.
  • With the new player object still selected in the Hierarchy, drag the “player anims” object on to the Animation slot. The Sprite Container slot should automatically fill with a reference to the “player” container object, if it doesn’t you can drag & drop that onto the slot.
  • Now you should see the player sprite in your scene and if you press Play in Unity, the sprite will animate through all of the frames in all of the animations. We don’t want the animation to play on start so uncheck the Play On Start checkbox.

Adding Collision To The Player

In order for the player to collide correctly with the ladder and rope colliders we’ll be creating later, we need to set the following.

  • With the the player “OTAnimating Sprite” still selected in the Hierarchy, check the check box next to Collidable. This will automatically add a Rigidbody component to the object.
  • Click the dropdown list next to Physics and select Custom from the list.
  • Under Transform, set the Scale Z to 1.
  • Change the Depth to -1.
  • Under Box Collider, set Center Y to -0.1 and Z to 1. Change Size X to 0.45, Y to 0.6 and Z to 0.4.

If you followed the steps above, the settings on the player sprite should look like the following image.

Click on the image to see all of the settings:

Changing the Depth to -1 and the Center Z to 1 on the Box Collider will position the Collision at 0 on the Z axis while moving the player sprite 1 unit towards the camera. This has 2 effects: it makes sure that the player will always be visible in front of the level sprites while keeping the collision at 0 on the Z so that it will collide with the ladder and rope triggers. It sounds kinda strange, but you can see how it should look in this screen shot:

2dGamePt3 Player Collision

Setting Up The Shooting Animation

We need to add another animating sprite so that when you press the fire button, you’ll see a bullet blob animate from the player and hit the ground.

The Shoot Animation:

  • Drag an Animation object from Orthello –> Objects –> Sprites into the Hierarchy. This will add a new object under OT –> Animations named something like “Animation (id=-4320)“. Rename this object to “shoot anim“.
  • With the new “shoot anim” OTAnimation still selected, adjust the settings to match those in the following image. To populate the Container field, drag & drop the “level” object from OT –> Containers on to the Container field. Remember that we already added the shoot sprite animation to the level sprite atlas in Part 2 of the series.

2dGamePt3 Shoot Sprite Animations

The Shoot Sprite

  • Next find the AnimatingSprite object in Orthello –> Objects –> Sprites in the Project tab and drag it into the Hierarchy, this will make a new object in the scene with a name like “Animating Sprite (id=-23050)“. Rename this object “shoot“.
  • With the new shoot object still selected in the Hierarchy, drag the “shoot anim” object on to the Animation slot. The Sprite Container slot should automatically fill with a reference to the “level” container object, if it doesn’t you can drag & drop that onto the slot.
  • Set the Transform Position X to -1 so that the sprite is position to the left of the player’s sprite.
  • Set the Depth to -1 so that the sprites will appear in front of the level sprites.
  • Set the Frame Index to 18.

Now you should see the shoot sprite in your scene and if you press Play in Unity, the sprite will animate through all of the frames in all of the animations. We don’t want the animation to play on start so uncheck the Play On Start checkbox.

We only want to see the shoot sprite when the player is actually shooting so uncheck the checkbox next to Mesh Render on the shoot sprite. This will hide the sprite in the scene until we show it again later with a script.

Parenting The Shoot Sprite

We want the sprite to move with the player and we also need to flip the sprite so that it’s either on the player’s left or right side depending on which way the character is facing.

  • Go to Game Object –> Create Empty
  • Rename this object to “shoot parent” and make sure the X, Y, Z Position on the object is set to zero.
  • In the Hierarchy, drag and top the shoot sprite on to the shoot parent so that the shoot sprite becomes a child of the shoot parent object.
  • Drag and drop the shoot parent object on to the player sprite so that it’s a child of the player.

If you followed all the steps so far, your Hierarchy should look something like the following image. Note that I put all of my level tiles under an empty game object named LEVEL to keep things organized.

2dGamePt3 Player Parenting

Note that in order for the scripts to work, the child objects under the player must be named exactly as shown in the above image.

Hooking Up The Scripts

We’re finally ready to add the scripts so that the player can move!

  • Download the player scripts and unzip the file somewhere on your hard drive.
  • Drag the Scripts folder from the .zip into your project’s Asset folder.
  • Create an empty game object by going to Game Object –> Create Empty
  • Rename the new object to something like “Scripts“.
  • Drag and drop the xa.cs file from the Project tab onto the Scripts object in the Hierarchy.
  • Drag and drop the player.cs and the playerAnims.cs files from the Project tab on to the player object in the Hierarchy.
  • Make sure that the player is positioned above a brick tile so that she has something to stand on. Remember that it’s the player’s Box Collider that actually collides with objects in the world and not the visible sprite object, so the box will be positioned at something like 0,0,-1 (X and Y can be anywhere in the level but Z should always be -1).

Now if everything is setup correctly, when you press Play in Unity the player should stand on a brick tile without falling through it. And if you press left and right on the keyboard the player should move and the run animations should play.

Describing how the scripts work is beyond the scope of this tutorial, but I did add comments to the scripts that should hopefully help you understand how everything is working. If you have questions about anything in the scripts, please feel free to ask in the comments below or email me directly.

Adding The Ladder Colliders

In order for the ladders to work, we need to add colliders to them.

Creating A Ladder:

  • Go to GameObject –> Create Other –> Cube
  • Rename the Cube to something like “Ladder“.
  • Open the Tag Manager by going to to Edit –> Project Settings –> Tags
  • Under Tags in the next available slot (probably Element 1) type “Ladder” and then in the next slot after that, type in “Rope” (without the quotes).
  • While we’re here, we need to add another layer. Under the next empty User Layer (probably User Layer 9), type “NoDraw” (without the quotes).
  • Now click on the Ladder cube you created before and change the Tag to “Ladder” and then change the Layer to “NoDraw“.

Hiding Objects In The Game View:

You’ve probably noticed that the Ladder collider is visible in the Game view but we don’t want to see these in the actual game. To hide them, we need to make a change to the camera.

  • Click on the Main Camera object in the Hierarchy.
  • Under Camera, drop down the list next to Culling Mask and click on “NoDraw” to deselect it. Now any object that is in the “NoDraw” layer will be hidden in the Game view.

Sizing And Positioning The Ladder:

Every ladder in the scene needs to have one of these Ladder colliders and we need to adjust the size of the Ladder colliders to match the height of each of the ladders in the level. The ladder collider needs to be 1 unit taller than the visible ladder – so if your ladder is 4 tiles (sprites) tall, then the collider needs to be 5 units tall.

  • Assuming your ladder is 4 sprites high: Select the Ladder collider and change the Scale Y to 5 (1 unit taller than the visible ladder).
  • Snap the Ladder collider to one of the lower corners of the bottom sprite using the Vertex Snap feature in Unity.
  • You can duplicate this object, resize the Y and snap it to all the other ladder sprites in your level.

Your ladder should look like this (click to see a larger version):
2dGamePt3 Ladder Trigger

Now if you press Play in Unity and then walk the player over to the ladder, she should be able to climb up and down the ladder, the player’s sprite should be playing the climb animation and you should be able to exit the ladder at the top and bottom levels and also fall off the ladder if you exit somewhere in the middle.

Adding the Rope Colliders

The rope colliders follow pretty much the same setup as the ladders.

Creating A Rope:

  • Go to GameObject –> Create Other –> Cube
  • Rename the Cube to something like “Rope“.
  • Change the Tag to “Rope” and then change the Layer to “NoDraw“.

Sizing And Positioning The Rope:

Like the Ladders, every rope in the scene needs to have one of these Rope colliders. But unlike the Ladders, the Rope colliders must be the same width as your rope sprites.

  • Assuming your rope is 4 sprites wide: Select the Rope collider and change the Scale X to 4 (Y and Z scale should be 1).
  • Snap the Rope collider to one of the lower corners of the bottom sprite using the Vertex Snap feature.
  • You can duplicate this object, resize the X and snap it to all the other rope sprites in your level.

Your rope should look like this (click to see a larger version):
2dGamePt3 Rope Trigger

Now if you press Play in Unity and then walk the player over to the rope, she should be able to climb left and right along the rope, you should see the rope hang animation playing and if you press the down arrow while hanging from the rope, she should let go of the rope and fall.

Conclusion

Now you have everything you need to make levels that support the player’s full suite of movements: running, ladder climbing and rope shimmy. In the next tutorial, we’re going to be adding the scoring system, breaking out brick tiles and picking up objects.

You can download the project up to this point and you can play the web version of the project here.

If you like this post, please be sure to say hi in the comments and follow me on Twitter and Facebook. Your support helps to keep these tutorial coming. This blog post is part of iDevBlogADay, a collection of indie developers writing about their development experiences.

Regarding The AI:

When I began this series, It was my intention to include enemies that could follow the player around the level using behaviors similar to the original Lode Runner game. However my time has become increasingly limited and my programming skills aren’t fully up to the task of recreating their AI so I might not be able to get AI into this the series.

If you are a programmer who would like to contribute an AI behavior solution to this tutorial series, please contact me.

More Tutorials In This Series

Make A 2D Game in Unity3D Using Only Free Tools Part 1
Make A 2D Game with Unity3D Using Only Free Tools Part 2

Share

Make A 2D Game with Unity3D Using Only Free Tools Part 2

Posted October 4th, 2011 in Tutorials, Unity3D, iDevBlogADay by Tim Miller

Welcome to part 2 of this tutorial series on making a Lode Runner-style 2D game with Unity 3D. In part 1, I introduced you to a bunch of free tools and scripts that we’ll be using and showed you how to setup your project. In this post, I go over how to create the level sprites and build your first level.

Of all the Unity plugins we covered in part 1, the main plugin we’ll be focusing on in this installment of the series is Orthello 2D. Orthello was recently updated with a lot of cool new features (as I write this, 1.6a is the latest version) so make sure you’re using version 1.6a or newer.

Initial Project Setup

We need to make a few changes to the project settings before we start making the sprites.

Build Settings:

  • File –> Build Settings…
  • Click on Web Player and then click Switch Platform. (You could leave this set to PC and Mac Standalone if you prefer.)
  • Close the Build Settings window.

Player Settings:

  • Edit –> Project Settings –> Player
  • Under Per-Platform Settings click on the little world icon (assuming you set your platform to Web Player in the previous step).
  • Click on Resolution and Presentation and change the Screen Width to 800 and the Screen Height to 600.

Render Settings:

Since you’re typically not going to use Unity’s lighting system in a 2D sprite-based game, we want to brighten things up in here by adjusting Unity’s default ambient light. This step is optional.

  • Edit –> Render Settings…
  • Click on Ambient Light and change the color to white (255, 255, 255, 255).

Initial Orthello 2D Setup

  • In the Unity Project tab, go to Orthello –> Objects and then drag the OT object into either the Scene or the Hierrachy tab.
  • In the Hierarchy tab, drop down the little arrow next to the OT object and then click on View.
  • Change the Pixel Perfect Resolution to 800 x 600 (same as we set for the Player Settings)
  • Change the Custom Size to 10

Now if you select the Main Camera in the Hierarchy, you’ll see that Projection is set to Orthographic and Size is set to 10. Orthello automatically changed the Projection from Perspective (Unity’s default setting) to Orthographic when you added the OT object into the scene. And When we changed the Custom Size on the Orthello View object to 10, it set the Main Camera’s Size to 10.

With a bit of experimenting, I found that with a screen resolution of 800×600 and an Orthographic Size of 10, a Cube at scale 1x1x1 will be exactly 30 pixels on screen which happens to be the exact size of the sprites we’re going to use to build the levels which should make it easy for us to stick to a grid when building levels.

At this point, your project should look something like the following image (click to see a larger image). Note that I also added a Cube to the scene for scale comparison.

Download the project up to this point.

Making The Level Sprite Atlas

Ok now that all that initial setup stuff is out of the way, it’s time to dig in and have some fun. The levels in Lode Runner were built using just a few simple tiles: Brick (digable), Concrete (un-digable), Ladder and Rope.

  • Download the source sprite .png’s and unzip the file somewhere on your hard drive.
  • Launch TexturePacker and then drag & drop all of the .png files from the sprites/level folder into the Sprites panel.
  • Then select all of the .png files in the sprites/shoot folder and drag those into the Sprites panel too.

Texture Settings / Layout:

  • Set Algorithm to Basic
  • Uncheck Trim
  • Uncheck Enable Auto Alias.

Texture Settings / Output:

  • Leave the Data format set to cocos2d.
  • Under Data File, click the little “…” button and browse the location in your project’s Asset folder where you want to store your sprites (I put mine in Assets/SpriteAtlases), name the file “level” and then click Save.
  • TexturePacker automatically adds the .plist extension to the Data File, but Unity wants the file to be .xml. So in the text field, replace .plist with .xml.
  • The Texture File path should already be set to the same location as the .xml file except that it will have a .png extension so there’s nothing to do there.

If you followed the steps above, then your settings in TexturePacker should look like this (click the image to see a larger version):

Now if you click the Publish icon in TexturePacker and then switch back to Unity, you should see a SpriteAtlases folder in the Project tab with the sprite atlas and a sprite data files inside.

We need to make a couple of changes to the sprite atlas in Unity so that it looks correct.

  • Select the level.png file in the Project tab. In the Inspector change the Filter Mode to Point.
  • Click the Override for Web box, set the Format to Truecolor and then click Apply.

Making The Level Sprites

Now it’s time to dig into Orthello and turn the atlas into sprites.

The Sprite Container:

  • In the Unity Project tab, expand the Orthello folders: Orthello –> Objects –> Sprites –> SpriteAtlas and then drag the SpriteAtlas-Cocos2D object into the Hierarchy.
  • In the Hierarchy tab, expand the newly created OT object and then the Containers object and you will see your new container with a name something like “Container (id=-6840)“. This is the Container that will hold all of our level sprites from the atlas we made so you can rename the Container to something obvious like “level“.
  • Drag the level.png from the Project, SpriteAtlases folder and drop it on the “OTSprite Atlas Cocos 2D” scripts Texture slot.
  • Drag the level.xml from the Project, SpriteAtlases folder and drop it on to the Atlas Data File slot. Now if you drop down the little Atlas Data arrow, you should see that it’s populated with all the sprite atlas data that TexturePacker generated for us.

Making An Animated Brick Tile:

The brick needs to have some animations on it that will play when it’s destroyed and when it regenerates so we need to make an Animation.

  • Drag an Animation object from Orthello –> Objects –> Sprites into the Hierarchy. This will add a new object under OT –> Animations named something like “Animation (id=-4320)“. Rename this object to “level anims“.
  • With the new OTAnimation still selected, adjust the settings to match those in the following image.
  • Under Framesets, set the Size to 3
  • To populate the Container field, drag & drop the “level” object from OT –> Containers on to the Container field.

  • Next find the AnimatingSprite object in Orthello –> Objects –> Sprites and drag it into the Hierarchy, this will make a new object in the scene with a name like “Animating Sprite (id=-23050)“. Rename this object “brick“.
  • With the new brick object still selected in the Hierarchy, drag the “level anims” object on to the Animation slot. The Sprite Container slot should automatically fill with a reference to the “level” container object, if it doesn’t you can drag & drop that onto the slot.

Now you should see a brick sprite in your scene and if you press Play in Unity, the sprite will animate through all of the frames in the animation. We don’t want the animation to play on start so uncheck the Play On Start checkbox.

Adding Collision To The Brick:

We’re going to need some collision on the brick later on so that the player knows when he/she’s standing on the ground.

  • With the brick object still selected in the Hierarchy, check the Collidable checkbox. This will automatically add a Box Collider and Rigidbody component to the sprite.
  • We also need to Tag the object with a specific tag and add it to a Layer. Go to Edit –> Project Settings –> Tags to open the Tag Manager.
  • Under Tags at the very top, drop down the little arrow and then type “Ground” (without the quotes) into the Element0 field and press enter. We’re going to need a few more tags later on so while we’re here, add another tag called “Ladder” and “Rope“.
  • We need some Layers too so under User Layer 8, type Ground and under User Layer 9 type Ladder.
  • Click on the brick object in Hierarchy and the drop down the Tag list in the Inspector and select Ground. Then click on the Layer drop down and select Ground from that list.

Turn It Into A Prefab:

Later on in the tutorial series we’re going to be adding some stuff to the brick object and making some changes so it’s a good idea to turn the object into a Prefab so that if you build a level with the brick and then and then want to make changes to it later, the changes will be applied all the prefab brick objects in your level. Making a prefab is super easy and will save you a ton of time later on.

  • Create a new folder in your Project and name it “Prefabs“.
  • Drag the brick object from the Hierarchy and drop it into the Prefabs folder in the Project tab.

Making The Static Level Sprites

Next we need to make the concrete, ladder and rope tiles. We’re going to use the same Container for these that we made before but instead of displaying them with an AnimatedSprite, we’re going to use the Sprite object.

Concrete Tile:

  • If your brick object is still sitting in the center of the Scene, move it to the side so it’s out of the way.
  • Drag & drop the Sprite object from Orthello –> Objects –> Sprites into the Hierarchy or Scene which will create a new object named something like “Sprite (id=-3700)“. Rename that object to “concrete“.
  • Drag the level object that we created earlier from OT –> Containers and drop it on to the Sprite Container slot in the Inspector.
  • Your sprite will appear but it looks like the brick sprite that we made before, that’s because the brick is the first texture on the Sprite Atlases index. Click and hold your mouse over the word “Frame Index” in the inspector (with the concrete object selected) and then drag the mouse to the right to scroll through the textures on the sprite atlas. The concrete texture is at index 14 so set it to that. The sprite should now look like a solid brick.
  • Check the Collidable checkbox to add collision to the object.
  • Drop down the Tag list in the Inspector and select Ground. Then click on the Layer drop down and select Ground from that list.
  • Drag the concrete object from the Hierarchy into the Prefabs folder in the Project tab to create prefab from the object.

Ladder and Rope Tiles:

The Ladder and Rope tiles follow most of the same steps as the Concrete tile.

  • Move concrete tile out of the way if it’s still sitting in the center or the Scene view.
  • Drag & drop a Sprite object from Orthello –> Objects –> Sprites into the Hierarchy or Scene and rename the object to “ladder“.
  • Drag the level object that we created earlier from OT –> Containers and drop it on to the Sprite Container slot in the Inspector.
  • Change the Frame Index to 15, the sprite in the Scene view should now look like a ladder segment. That’s all we need to do on the ladder tile for now.
  • To make the Rope tile, duplicate the ladder sprite in the Hierarchy and then rename it “rope“.
  • Change the Frame Index to 17 so that it looks like a black cube with a white line across the top (that’s our rope tile!).
  • Now make prefabs from the ladder and rope by dragging each of the objects from the Hierarchy into the Prefabs folder in the Project tab.

Making The Bottom Border:

Now we have all the sprites necessary for making levels, but before we start we need to make a border object that will sit at the bottom of the screen. The border will give the player and enemies something to stand on if there are missing bricks along the bottom row and it will also give us something to snap to so that the levels will adhere to a nice grid.

  • Go to Game Object –> Create Other –> Cube and rename it to “border bottom
  • Change the Transform Position to X: 0, Y: -10.3, Z: 0
  • Change the Transform Scale to X: 26, Y: 1, Z: 1
  • Drag and drop the border bottom object from the Hierarchy into the Prefabs folder in the Project tab to turn it into a prefab.

A small amount of the cube should be visible above the bottom of the Game view and it shouldn’t quite be all the way to each edge. The cube is pretty ugly with the default white material, so let’s make a material that matches the color of the bricks.

  • Create a new folder in the Project tab and name it Materials.
  • Right click on the Materials folder and go to Create –> Material and then rename the new material “border
  • Select the border material and then in the Inspector click on the white area beside the little eye dropper icon, this will open up the color picker.
  • Change the RGBA settings to R: 159, G: 2, B: 0, A: 255 and then close the color picker.
  • Drag the border material and drop it on to the border bottom object in the Hierarchy to apply the material. The border should now be the same color as the bricks.

Change The Background Color

We’re almost ready to make a level, but first lets change the background color to black.

  • Select the Main Camera and then click on the color swatch next to Background.
  • Change the RGBA settings to 0,0,0,255. The background in the Game window should now be black.

Making A Level:

Whew! It took a few steps, but now you have everything you need to build a bunch of levels. Well almost everything – you still need a player, enemies, a pickup and a few other things which we’re going to cover later on in the series.

At this point you can just start duplicating the brick, concrete, ladder and rope tiles around the scene to make a level. BUT before you do, here are a few tips:

  • In the Scene view, click on the drop down list directly under the Scene tab – it might say something like “Textured” and change the option to Tex-Wire.
  • You can use Vertex Snap to easily align objects – in the Scene view hold down the V key and hover the mouse over any of the 4 corners on one of your tiles and you’ll see that the manipulator will snap to the closest corner. Click the left mouse button when the handle is over a corner of the sprite that you want to snap from and then drag the object to another sprite corner to align it tightly with that tile.
  • Remember that bottom border cube we made before, well you can use that as a base line for snapping your cubes so that you can build the entire level on a grid. Grab one of your tiles and snap the lower left corner to the upper corner of the bottom border object. Note that you don’t have to worry about snapping on the Z axis since Orthello doesn’t allow you to move objects along the Z axis.
  • You can also select several tiles at the same time either with shift+left click or by dragging an area around a bunch of tiles. Duplicate those tiles and then use Vertex Snap to snap them to other tiles in the scene.

Here’s what my initial scene looks like as I start by building the level from the bottom border object (click to see a larger version):

And here’s what a finished level looks like (click to see a larger version):

Conclusion:

I hope you enjoyed this post and learned a little more about how to make 2D games with Unity. In the next post we’re going to be adding a playable character so you can actually run around in the levels.

If you like this post, please be sure to say hi in the comments and follow me on Twitter and Facebook. Your support helps to keep these tutorial coming. This blog post is part of iDevBlogADay, a collection of indie developers writing about their development experiences.

Download the project up to this point.

Further Reading

Make A 2D Game in Unity3D Using Only Free Tools Part 1

My previous tutorial series that used Sprite Manager 2 for the sprite display and animation duties:

Share

Make A 2D Game in Unity3D Using Only Free Tools Part 1

Posted September 19th, 2011 in Tutorials, Unity3D, iDevBlogADay by Tim Miller

Make A 2D Game in Unity3D Using Only Free ToolsIn this iDevBlogADay post, I’m going to kick off a new tutorial series that’s aimed at making a 2D sprite-based game in Unity3D using only freely available tools, scripts and plugins. This isn’t the first 2D in Unity3D tutorial series I’ve done here – I previously did a 5 part series that used Sprite Manager 2 for the sprite display and animation duties. This time around, I want to show you how to make a game basically for free and I’m going to up the ante in this new series by adding in some other great plugins like iTween and A* Pathfinding.

Over the course of this series, we’re going to recreate one of my all time favorite C64 games: Lode Runner! I always wanted remake Lode Runner for my own amusement but also as a way to try out some things I haven’t figured out how to do yet – like creating an AI that can follow the player on ladders.

In this first installment, I’m going to introduce you to the tools we’ll be using and show you how to set them up in Unity. In the next part, we’ll dive in and start making the game. While we’ll be using the free versions of these tools, most of them also have paid options which unlock additional features.

Tools:

  • Unity3D: You probably already know that Unity3D is great tool for making 3D games, but it’s also pretty great at making 2D games with the addition of a few scripts and plugins. We’re going to be using the free version of Unity which will allow you to publish games to web as well as PC and Mac standalone but you can easily make the game work on iPhone or Android with a paid upgrade to those versions.
  • Orthello 2D Framework: There are several different sprite plugins available for Unity, the most popular being Sprite Manager 2 which I have used extensively and wrote about in my earlier 2D game tutorial series. I recently found myself looking for an alternative to SM2 and while doing research, @jeedee mentioned that he was quite satisfied with Orthello so I thought I’d try it out. In some ways it’s not as easy to use as some of the other plugins out there – you have to make your own sprite atlases for example – but for a free plugin it offers a ton of great features and will work perfectly for our 2D project.
  • iTween: iTween is my go-to animation system for every one of my projects here at Rocket 5. It’s ideal for animating everything from enemies to UI and it’s usually the first script I install when starting a new project.
  • A* Pathfinding Project: A* Pathfinding is probably the most widely used pathfinding system available for Unity. It’s fast, powerful, easy to use and since there’s a free version it’s perfect for our project.
  • TexturePacker: TexturePacker is a standalone app that makes it easy to create sprite sheets from your textures. You could use an image editing app like PhotoShop, Acorn or Gimp to make your atlases, but Orthello 2D recently added direct support for atlases generated by TexturePacker which should make things easier for us later on.

Starting A New Project:

  1. Install the latest version of Unity and then create a new project by going to File -> New Project, click the Set… button and browse to a location on your drive where you want to save your Unity projects, enter a name for the project and then click Save. Optionally you can select any packages that you want to import into the new project, I didn’t import any packages into my new project. Finally click the Create Project button.
  2. Create a new folder in your Project view and name it “Scenes” and then save the current scene by going to File -> Save Scene As, open the Scenes folder you created in the previous step, name it “level1” and then click Save.

Installing Orthello 2D:

  1. Open the Asset Store by going to Window -> Asset Store, search for “orthello2d“. The page for the plugin should display, click the Download button. Or download the latest version from the website, unzip the archive and double click on orthello.unitypackage.
  2. When the Import Package window appears, make sure that all the checkboxes are checked and then click Import. After a few seconds you should see an “Orthello” folder in your Project view.

Orthello 2D Initial Setup:

The Orthello website has tons of detailed information on setting up and working with the plugin so be sure to take a look. Following are my simplified steps to get you started.

In order for Orthello to work in the scene, you’ll need to setup a few things first. Note that you will need to repeat these steps in every new scene you create.

  1. In the Unity Project view, go to Orthello -> Objects and then drag the OT prefab into either the Scene view or the Hierarchy.

The OT prefab acts as a parent for Animations and Sprite Containers that we will be adding to the scene later on. Adding the OT object to your scene will also automatically make some changes to the Main Camara so that it will work properly for a 2D game – the main things are it changes the Projection to Orthographic and sets the Size to 332 (332 is kind of a weird size, but that’s the size that Orthello likes).

Installing iTween:

  1. Open the Asset Store again by going to Window -> Asset Store, search for “itween“. The page for the plugin should display, click the Download button.
  2. When the Import Package window appears, make sure that all the checkboxes are checked and then click Import. After a few seconds you should see an “iTween” folder in your Project view. If you want you can delete the “ReadMe!” and “Sample” folders if you want but they won’t hurt anything and it’s a good idea to look at the sample scene if you’ve never used iTween before.

Installing A* Pathfinding:

As I write this, the free version of A* Pathfinding is not available for download from the Unity Asset Store (the paid version is though).

  1. Go to the website, click on Download Latest Version and then click on A* Pathfinding Project in the Download area which should download a file named PathfindingProject_Free.unitypackage onto your computer.
  2. Double click on PathfindingProject_Free.unitypackage which will open the Importing Package window in Unity. Make sure all of the checkboxes are checked and then click Import. You should now see a folder named “AstarPathfindingProject” in your Project view.

A* Pathfinding Initial Setup:

Be sure to read the “getting started” page in the A* Pathfinding Documentation for a full explanation of how to setup A*. Here are my simplified steps to get you going.

  1. Create a new empty game object by going to GameObject -> Create Empty.
  2. Make sure that the x,y,z position of the game object is at zero and then rename the object to “A*“.
  3. Add the Astar Path script to the game object by going to Component -> Pathfinding and then click on Pathfinder.
  4. With the A* object selected in the Hierarchy, you should see Astar Path script’s options in the Inspector. At the top of the script you should see a message that says “Do you want to enable Javascript support?”. Since all of the scripts used in this tutorial are going to be written in C#, you can go ahead and click “No” (you can change this later in the settings if you want).

Conclusion:

If you followed all of the steps above, then your project should look something like this (click to see larger image).

The cool thing about the project is that you can use this as a starting point for creating all kinds of 2D games so keep this around as a base for starting new 2D projects (although be sure to check for the latest versions of the scripts).

Further Reading

Make A 2D Game with Unity3D Using Only Free Tools Part 2
Make A 2D Game With Unity3D Using Only Free Tools Part 3

Share

Summer 2011 Studio Update

Posted September 13th, 2011 in Dev Diary by Tim Miller

skyline iconThings have been a little quiet on the blog lately but rest assured that we have tons and tons of great things happening here at Rocket 5. We currently have 2 iOS games in development and over the summer we shipped a new photo app called “Eyeball Me” for an overseas TV show.

XS Force is alive and well but doesn’t look like it’s going to release in time for our previous “coming summer 2011″ promise, we’re all kind of bummed about that (making the promise I mean). We got a lot of great feedback from friends and the press at GDC so we decided to push the gameplay in a new direction which we’re all really excited about.

Alarm DogThe really big news here is that we’ve started working on a new game with Mujia Liao, a super talented artist from right in here in Toronto. And that’s not all! Cathy Feraday is coming on board to do the animations for the game (and for XS Force too) so there’s no doubt that this will be one of our best and biggest games yet. We’re not ready to announce any details about the game at this point but this little dog is one of the characters that will be appearing in the new game.

We’re going to be revealing a lot more cool stuff as XS Force and the “other game” (can’t wait to tell you!) get a little further along in development so be sure to follow us on Twitter, Facebook and right here at rocket5studios.com to keep up to date on all the latest.

And finally I just wanted to say thank you to all the people who visit our site and play our games. Last month rocket5studios.com had over 18 thousand hits and our games and apps were downloaded over 34 thousand times! We wouldn’t be able to do this without your love and support.

-Tim

Share