Friday, February 27, 2015

Zombie Spitter Sales Report


Okay, so here is the report for the zombie spitter

This is the first game that I am trying with free model and "in app purchase" + chartboost

so as you can see, total download is 313 but I only get $21.33 from the "in app purchase" and $1.52 from the chartboost

so does it mean the Free + in app purchase losing to "paid app" ?

it definitely seem like it

but there are one major error on my part
1. My game have some error that it do not save properly that it might anger the user and they uninstall the game
(I have fixed it after 1 month but user gone will never come back)


Learning how to create cube in Unity using script

So today I am learning how to create object using scripting

below is some youtube tutorial i learned from
https://www.youtube.com/watch?v=642o94MNfs4

and below is the wiki page
http://wiki.unity3d.com/index.php/ProceduralPrimitives

Friday, February 20, 2015

Unity object follow your mouse tutorial

Okay, so let say I am building a spaceship game, and I want the spaceship to follow my finger or mouse whenever i drag the screen, below is how I do it

/////////////////////////////////////////////////////////
public transform mybody;
Vector3 mousePosition;
Vector3 targetPosition;

void FixedUpdate () 
{

        if (Input.GetMouseButton(0)) 
        {
            mousePosition = Camera.main.ScreenToWorldPoint(new Vector3 (Input.mousePosition.x,Input.mousePosition.y,7.59f));


            targetPosition = new Vector3(mousePosition.x,mousePosition.y,mousePosition.z+1.5f);

            mybody.position = Vector3.Lerp(mybody.positiontargetPosition0.1f);
        }

 }

/////////////////////////////////////////////////////////

Drag your spaceship transform to the "mybody"

Lets get down the basic
1. void FixedUpdate () , this function will update every 0.02 seconds

2. if (Input.GetMouseButton(0)) , this mean when the mouse button is click, or finger is pressing down on the iphone

3. Input.mousePosition
=======================
a. Input.mousePosition.X you will get value 0 to 800 (max screen width)
b. Input.mousePosition.Y you will get value 0 to 600 (max screen height)

but, 
a. your spaceship transform.x (value -6 to 6)
b. your spaceship transform.z (value -4 to 4)

4. So you can see both coordinate is not sync, so you need the "Camera.main.ScreenToWorldPoint"
to convert your mouse coordinate to your camera coordinate, and store it inside "mousePosition"

-the "7.59f" is how far your camera from the (0,0,0) point, you can check in unity main camera.transform.position and see the z is how much

5. After you convert the mouse coordinate to your spaceship coordinate, you store them into your "targetPosition", you can see i put +1.5f on z position because i want the spaceship appear higher so that my finger do not block the spaceship 

6. Finally you move your ship slowly from starting position to target position by 0.1f per update by using the Vector3.Lerp function


note:
For simpler code, you can do this

/////////////////////////////////////////////////////////
mybody.position = Camera.main.ScreenToWorldPoint(new Vector3 (Input.mousePosition.x,Input.mousePosition.y,7.59f));
/////////////////////////////////////////////////////////

then your spaceship will teleport to anywhere your finger press

idle game timer tutorial

Below is a simple idle game timer tutorial for Unity

1. When the user browse away or exit the game, you need to save the current time immediately 


/////////////////////////////////////////////////////////
void savegame(){
    System.DateTime epochStart = new System.DateTime(197011000System.DateTimeKind.Utc);
        curtime = (int)(System.DateTime.UtcNow - epochStart).TotalSeconds;
        
        PlayerPrefs.SetInt("curtime",curtime);

}
///////////////////////////////////////////////////////////

the above function is a save function where you save the time using "epoch time" meaning how many seconds since year 1970, so you can save it into the integer variable "curtime"

example 1424451609

When the user load the game, you do as below

///////////////////////////////////////////////////////////
void loadgame()
{


loadtime = PlayerPrefs.GetInt("curtime");

        System.DateTime epochStart = new System.DateTime(197011000System.DateTimeKind.Utc);
        curtime = (int)(System.DateTime.UtcNow - epochStart).TotalSeconds;



        int exit_duration;

        exit_durationcurtime - loadtime;
        

   

}
///////////////////////////////////////////////////////////

So when you load the game back, you get the curtime using epoch way then you get the loadtime from your saved, so you can calculate out the exit duration

example, the user exit game on
1424451609 (loadtime)

then he come back on
1424451629 (curtime)

So you know he exit for 20 seconds, and you take this to apply to your games accordingly

///////////////////////////////////////////////////////
void OnApplicationFocus(bool focusStatus
{
        //focus status 1 mean pause
        if(focusStatus==false)
        {
            Debug.Log ("pause");
            savegame();
        }
        if(focusStatus==true)
        {
            Debug.Log ("unpause");
            loadgame();

        }
}
///////////////////////////////////////////////////////

So in unity, you need to save the game when the user lose focus, because maybe he is playing other app, or the phone is auto close, then you save the game, then when he come back, load the game back and apply the "exit_duration" you calculated to your game




Friday, February 13, 2015

I launch my first multiplayer games

After around 45 days of coding, finally I managed to launch my first multiplayer games into kongregate, play it free at kongregate



http://www.kongregate.com/games/fundurian/multiplayer-space-shooter

Tuesday, February 10, 2015

designing boss ship in blender

Designing boss ship in blender


Designing the boss ship shooting

I want the boss look very big and shooting tons and tons of bullet

Sunday, February 8, 2015

Destroying Enemy using Photon Network RPC call

So I hit this problem with the synchronization problem with Photon Network where example

Player 1 Host the game
Player 2 Join the game

both player fighting the same enemy1

Player 2 kill the enemy but player 1 still see the enemy

This is because if you are using the

PhotonNetwork.Destroy(gameObject);

Player 2 cannot call this function because he is not the owner of this object, only Player 1 can call this function, to fix this, we must use the RPC call as below


/////////////////inside enemy.cs//////////////////////////////////////////////////

[RPC]
    public void gethit(float getdamage)
    {
        if(PhotonNetwork.isMasterClient)
        {
            life-=getdamage;
            
            if(life<=0.0f)
            {
                
                PhotonNetwork.Destroy(gameObject);
            }
        }
    }

///////////////////////////////////////////////////////////////////////////////

first, inside your enemy script, you put the tag [RPC] on top of your function

then, make sure only master client do the deducting life because you dont want everyone deducting life, example if 5 player all do the deducting life the enemy get 1 bullet but deduct life 5 times

then finally, only "MASTER CLIENT" can call the PhotonNetwork.Destroy because he own the object

//////////////////////////inside bullet.cs ////////////////////////

void OnCollisionEnter(Collision collision
    {
        
        if(collision.collider.gameObject.GetComponent<enemy>())
        {
            //collision.collider.gameObject.GetComponent<enemy>().gethit(damage);

            collision.collider.gameObject.GetComponent<PhotonView>().RPC ("gethit",PhotonTargets.
MasterClient,damage);


    }


/////////////////////////////////////

Then, inside your bullet script, where originally, you will use the

collision.collider.gameObject.GetComponent<enemy>().gethit(damage);

Now, you use

collision.collider.gameObject.GetComponent<PhotonView>().RPC ("gethit",PhotonTargets.MasterClient,damage);


So the original one is to ask the enemy script to execute the "gethit" function for "SELF"
-> example player 2 kill the enemy, player 2 calling the "gethit" function but not player1

the new one is to ask the photon view RPC call to ask "MASTER CLIENT" to execute that gethit function
-> so if the room have 3 player, only "MASTER CLIENT" will call the "gethit" function


Sunday, February 1, 2015

Update on my spaceship games

Okay, so it seem like a very long and tedious task to finish this spaceship games


below task is the one I finished
1. Main ship can be controlled
2. Main ship can shoot
3. Main ship bullet can hit enemy, can reduce enemy life
4. enemy ship can shoot
5. enemy ship bullet can hit main ship, can reduce life
6. 3 type of enemy ship, 3 type of rock
7. 3 type of bullet type
8. shooting sound
9. when health reach 0 of all object will die and will explode for all object
10. single player mode
11. enemy will appear randomly each 5 seconds with random number

below task is the one not yet done
1. upgrade mechanic
2. 300 level
3. item collection during in game
4. and many more