Saturday 3 January 2015

Hill Climbing Like Physics

Hi,

It is just a rough and quick prototype for 2D game having physics like of Hill Climbing Race.
Please play the game and let me know about your feedback, You can also download the source.



Playable File : https://www.dropbox.com/s/95kpdxqngerpkwp/HCProto.exe?dl=0
Source : https://www.dropbox.com/s/tzbl4gmundwc1lw/ProtoHC.rar?dl=0

Thank you.

Sunday 28 December 2014

Catch The Words:

Hi everyone, I have recently worked on a game using Unity 2D. Here is the sample game source files using following features:


  • 2D collision.
  • Text to mesh conversion.
  • Accelerometer for player movement.
  • Co-routines.
  • NGUI basics.
  • Vertical health bar.
  • Lives
 Please play the game download the source code for code.
Link : https://www.dropbox.com/s/t6a3lhplfcdn90p/SKK3.rar?dl=0 

Thank you.


Monday 8 December 2014

Applying force in opposite direction of collision:

After banging my head to each and every script available and possible resource. I came up with the following code  It might help other people with the problem like kicking a football or 8-ball game or etc. The code is for 2D games in Unity, So here it is


public float explosionStrength = 10.0f;
void OnCollisionEnter2D(Collision2D collision) {
Collider2D collider = collision.collider;
 //Debug.Log("Collision with ball "+collider.name);
 if(collider.name == "FootBall")
 { GameObject target_=GameObject.Find("FootBall");
    Debug.Log("Velocity is "+target_.rigidbody2D.velocity.normalized );
    Vector2 forceVec = -target_.rigidbody2D.velocity.normalized * explosionStrength;                  target_.rigidbody2D.AddForce (forceVec, ForceMode2D.Impulse);
    Debug.Log("Collision with ball");
 }

 }

Saturday 19 July 2014

Flappy Bird using Unity

This time I am going to share a tutorial to make a game like "Flappy Bird".  You can download the project from dropbox link or you can go through the following tutorial to get the jist of it.

Lets start by making a 2d Game in untiy 4.x. Follow the tutorial and you will be ready to make a game like this one.

1. Make a 2d project and name it what ever you like,as I named it as Flappy Bird.

2. Second step is very important always I am repeating it always organize your projects it helps in any kind of modification. So make new folders as Prefabs, Scenes, Scripts and Textures. We will add more folders if required. So go and make folders.

3. First of all look for a wallpaper for you game. Do not judge mine as it was a random pick haha. So lets move forward - Copy the image into textures folder and drag it to the screen area(Scale it to fit the screen in my case it is x=2.4 and y=1.4)

4. Now it's time to make our bird goto google and search anything like "flappy bird png" , "flappy bird tga" or "flappy bird texture" you will surely find something of use, Copy the image to the textures folder and drag that one too to the scene. My image is hi-res that is why I have scaled it down. Name it as "Bird"(We are not using any sprite sheet because purpose of the tutorial is somewhat different I will cover that part in some other tutorial).

5. Lets add some physics to our game, add the component "Rigidbody 2D" to the "Bird". Save the scene in Scenes folder and press play and it should fall.

6. Lets make the jump script. Make a new C# script in Scripts folder and name it as Jump. Code is as follows

using UnityEngine;
using System.Collections;
 public class Jump : MonoBehaviour {
 // Use this for initialization 

 public Rigidbody2D bird;

  void Start () { 
 } 

//Update is called once per frame

  void Update () { 
         if(Input.GetKeyUp("space")) 
         {        bird.velocity=Vector2.zero;
                  bird.AddForce(new Vector2(0,250)); 
         } 
  } 


Script is easy to understand it checks for the input. Once it get the input it will turn the velocity of our "Bird" to zero and add the upward force for jump.
Make an empty Gameobject name it what ever you like and attach the script to it or you can attach the script to the main camera(I have used the later approach). At last add the "Bird" gameobject to the instance if the script.

7.Next part is making obstacles for the game. Search something like "mario pipe png" in google images you will find the obstacles. Create an empty Game object in the editor. Name it as "Obstacles pair" drag the png you just downloaded to the textures folder. Now add it 2 time to your scene. Make them children of "Obstacles pair" name one as "obstacle1" and other as "obstacle2". Now final step is rotating the obstacle. In my case I had to give "obstacle1" rotation of 180 degrees at z axis. And you should give the distance of your bird+0.3 (or more) between your obstacles so that bird can pass between them. Your game should look like this


8. Now you have to attach a rigidbody to the obstacles so that you can give it some velocity. Now here are the actions you have to take to complete this phase.

  • add a component of "Rigidbody2D" to the parent object and mark it as "is Kinematic". Anything which is marked as "is Kinematic" will stop responding to gravity.

    •   }

      // Update is called once per frame
      void Update () {

        }
      }
  • Create a new C# script in your scripts folder and name it as "MoveObstacle". Code is given below
    using UnityEngine;
    using System.Collections;
    public class MoveObstacle : MonoBehaviour {
    public Vector2 velocity = new Vector2(-3, 0);
    // Use this for initialization
    void Start () {
    rigidbody2D.velocity=velocity; }

    // Update is called once per frame
    void Update () {

      }
    }
  • Script is self explanatory you make a new velocity variable and apply that velocity to obstacle pair gameobject. As it is not a sidescoller game so we don't have to move environment and player we just have to move obstacles. Apply this script to "Obstacles pair" gameobject.
9.  We have to generate obstacles every few seconds.
  • First of all make an empty prefab name it as "ObstaclesPair".
  • Drag the "Obstacles pair" gameobject from the scene onto it.
  • Now make a new C# script named as "GenerateObstacle" in Scripts folder and attach it to Main Camera as it will generate obstacles with the passage of time. Bode is below(I am not showing randomness in heights as its your work to do :D )
  • using UnityEngine;
    public class GenerateObstacle : MonoBehaviour
    {
    public GameObject obstales;
    public bool gen=true;
    public float seconds=0;
    public int updateCounter=0;
    public int maxRange=170;
    // Use this for initialization
    void Start()
    {
    }
    void Update()
    {

    if(gen)
    {
     gen=false;

     Invoke("GenerateNewObstacle" , Random.Range(4,8));
    }
    else
     updateCounter++;
     if(updateCounter >= maxRange)
    {
     gen=true;
     updateCounter=0;
    }
    }
    void GenerateNewObstacle()
    {
      Instantiate(obstales);
    }}

10. So now the turn is of killing the player. There could be 2 reasons for it either Bird has touched the ground or sky or it has collided with obstacle. Following are the steps the implement these features
    • Apply Box collider 2D to the Bird gameobject.
    • Appy polygon collider 2D to the both of obstacles and update your Prefab for obstacles.
    • on collision of birds Restart the level.
    11. Download the project to see how does all of it works.

    Sunday 29 June 2014

    Penalty shoot-out using Unity3D

    Hi

    I have made this game prototype on the weekend . Kindly let me know if you think it needs other modification.





    It basically works without gravity and new ball is spawned on the same position once it is is kicked using a gesture. I know it's a rough one but it can convey the gist of the project. :)

    Here you can download the project : Link

    Wednesday 18 June 2014

    Sniper shooter Part 2

    Sniper shooter prototype part 2:

    Lets set up cameras for the game. We need two cameras for the gun after setting them up we will add the cameras to the gun prefab so that it can be reused easily. Follow the steps for this purpose

    • Download the following textures of crosshair for normal and zoom camera 



    Normal cam crosshair

    Zoom cam crosshair


    • Make an empty game object in your scene name it as player or whatever you like.
    • Make GunsAndHands prefab child of this gameobject you created and change its position to (0,0.7297325,0).
    • Now make another empty gameobject in the scene (name it cameras) make this gameobject child of "player" gameobject then change its position vector to (0,1,0)
    • Create a camera gameobject in the scene name it as MainCamera change the tag of this gameobject to "MainCamera"(you will have to create a new tag) with the following settings



    • Make the MainCamera gameobject child of "cameras" and change its position  to (0,-0.177351,0)
    • Now the next camera will be of zoom so it will a have a lesser Field of view(FOV)
      and more far clipping than main camera so create a new camera with the following settings and name it as ZoomCamera with the following settings
    • Make ZoomCamera child of cameras and change its position to (0.3755417 , -0.2398739 , 3.198844)
    • Now its time to putcrosshairs in place. We have to put transparent planes in front of cameras and then apply the textures. As plane available in unity is not transparent and it consists of lot of vertice so here I have a custom plane for this purpose. You can download the project and find how crosshairs work.
    So this is how our game should look like by now


    You can download the unity package from here  (PlayerPrefab is the updated one)

    Tuesday 17 June 2014

    Sniper Shooting prototype (Part 1)

    Hi,

    First of all what we need is a Sniper gun model (.fbx format) with the animation like


    • idle
    • walk
    • reload
    So as I know that most of the game devs are not in to the 3D asset development so I am going to share the model of gun in this post. We will use the First person camera view with model (animations are included in the unity package).

    Please download the package, drag the gun into your scene and see how the animations works. The motion which makes the sniper gun move little bit in and out of the axis because of wind pressure is part of idle animation so, it will help in making game little more interesting. (I have not made this model so we must thanks the random guy over who has shared it over the internet)

    You can download from here