2D Angry Birds Clone Game Tutorial – Unity3D (C#)

2D Angry Birds Clone Game Tutorial – Unity3D (C#)


Play Demo

Everybody knows these angry guys. They try to break down the walls and kill enemies. Player pulls the string and throws them. In this tutorial, we will create the visuals and write some codes to throw them.

Open Unity3D and create a new 2D project. As always, you can find the sprites from google. Import them and start to create the world.

You need a sky image for the background, a ground image, slingshot image and bird image. Place them wherever you want except the slingshot. While editing sprites, place the center circle on the edge of bands for both branches. This will help us to create strings easily.

Screen Shot 2015-06-02 at 22.15.26

Slingshot image should include separately 2 images for each branch because birds will be thrown between them and we will put them different order in same layer.



Make #2 (back) parent of #1 (front) and stick together. Add Rigidbody2D (“Is Kinematic” is selected).

We will create strings by Line Renderer. So, add Line Renderer both of them. You can create a material and use it for the color of strings. Click “Parameters” and change start-end widths as you want. I used 0.06-0.04 for #2 and 0.07-0.05 for #1. #2 is a little bit thin because of perspective view.

For the bird, add a Circle Collider 2D and add a Rigidbody 2D. Create a 2D Physics Material named Friction and drag it in to the collider material.

Screen Shot 2015-06-02 at 22.22.54 Screen Shot 2015-06-02 at 22.21.03 Screen Shot 2015-06-02 at 22.20.55

We need to add a collider to the ground. Add Box Collider 2D or Edge Collider 2D.

Create a new layer and add all visuals to it because we should place them in an order. The order should be: Sky-0, Back Slingshot-1, Bird-2, Front Slingshot-3. We will create strings for each branch of slingshot in the same order.

Lets write some code. Create a C# script named DragBird and open it.

This code uses Line Renderer to create strings. In additional, we created a bool to check if player clicks on the bird. Player clicks on the bird, drag and release as you know. Kinematic should be disabled when you release the bird.

Dragging() function controls dragging the bird. It gets mouse position and distance from the slingshot. mousePos.z = 0 because we use 2D and we do not need z vector.

StringUpdate() function provides an update for the string. While you drag the bird, strings follow it as ray.

We calculated radius of birds collider to attach the strings to its edge. Also, strings are disabled when bird is released with velocityX. That’s it. Attach this script to the bird. Now, we need a script to make camera follow the bird. Create a new C# script named CamFollow.

This script follows the bird between two boundries. Back to Unity and create two boundries. You can use empty game object as a boundry and duplicate it.

Screen Shot 2015-06-03 at 14.34.36

Enjoy it! Add some blocks and enemies to destroy. Also you may add some sounds and animations.

You can download source code here.


©Coffee Break Codes – 2D Angry Birds Clone Game Tutorial – Unity3D (C#)

Leave a comment

Your e-mail address will not be published. Required fields are marked *

9 thoughts on “2D Angry Birds Clone Game Tutorial – Unity3D (C#)