Pages

Thursday, December 23, 2010

Confused?

I'm currently in the final semester of my 3rd year of studies in University now, and just one more year, two more projects, and I'll be off saying bye bye to my Uni and work in some (probably) good company later on.

It sounds like a great ending, but the more I think about it, the more I felt useless, as I can only wish for those "successful" things to happen in the future after I graduated, instead of being "successful" while I'm still in Uni... It's like I'm gonna regret about my Uni life when I started working, just like how I regretted not doing anything really meaningful in high school.

Not that I don't have anything to be proud of now, I do have one currently, it's my first Unity game, EcoTat... It was my first and somehow complete game I designed and developed entirely. It's also something I created when I've pushed myself up to my limit, during the time when I first started using Unity and scripting in Java; building a turn-based fighting system...

Anyway, my progress had gone worst than before in the following semesters: I developed a vehicle-adventure game, and a 3rd person shooter adventure game based on 'the boring Tim Burton's movie, Alice in Wonderland', which were not entirely complete. Particularly the Alice game, where I completely stop its development after the presentation is over, though the game wasn't even half complete during the presentation day, as the scope I set was a bit higher than the others.

And my latest work, a job-searching application did not meet up to my majoring coordinator's expectation. To be quite frank, I've been really lazy lately, and developed the application within a week's time (again?). Furthermore, I've had zero interest on the project, as my primary interest is on game development. The output and reception were worst than I expected...

But from these past experiences, I've really learned a few things, something values which I, and probably the rest of the young developer/beginners may need in the future:
1. Never look down on projects - 
As boring and uninteresting a project may seems, you should always give in your best, because whether of not it's in the real world or in your University life, you always have to develop stuff that satisfy your client, which in a student's case, the lecturer is the client.
2. Create stuff that isn't possible in real life - 
My latest project revolves not only the interactions but also the architecture and design of my virtual environment. One of the review by my lecturer is that, the building and environment I made for my application was too common in the real world. I'm building a virtual world here, and it's a place/world where impossible ideas from the real world can be fulfill even with just a slight creativity.
3. Your lecturer sucks doesn't mean you are too - 
To be quite frank, my current majoring lecturer was the worst I had throughout my studies in this University. He's not like rude or not being friendly or anything, he's just not up to par. And during the semester when my progress had gone from good to bad, he was my lecturer of the semester. Anyway, I realize later on that I blame the others too much, and never think about what my major problem is here: I'm too lazy (probably from )
4. Do what you are suppose to do, stuff within your range - 
After facing so many failures in these development stuff, particularly it's because that my application wasn't well-received by everyone, I realize something... I'm not just a game programmer... I'm a freaking game designer. And I'm like nothing if compared to those real Computer Science and IT people... I've been focusing so much on programming that I rather give up on my designing time just to make better technologies for my applications/games. This is a wrong step, and I understand it now... 
5. Project finished within a short time is not always good - 
While some developers may have been talented for developing games within a short time during Ludum Dare. But you can never do the same when working on a school's project or for a client (lecturers). Doing a project within a short time means, less game design, less interaction ideas and thought-out, less focus on the game project, and less chance of it getting tested by anyone other than yourself, etc... Means you will have no idea on whether the project is gonna be good or not if you are not able to develop a prototype first for user testing... blah, blah, blah, and get pawned by critics later on...

...
I do remember there's still some more... but that's all for now, I'll update more when I think of them...

Unity3d + C#: Rect.Contains(Correct mouse postion)...

When using the Contains function:
void Update() {
    buttonRect = new Rect(20,20,50,50);
 
    if (buttonRect.Contains(Input.mousePosition))
    {
        print("haha");
    }

void OnGUI() {
    GUI.Button(buttonRect, "");
}

I realize that the phrase "haha" will be printed in the compiler only when the mouse position is at Rect(20, Screen.height - 20, 50, 50), instead of Rect (20, 20, 50, 50). So what happen is that the origin (0, 0) of the mouse's position starts at the bottom left of the screen... instead of the top left.

To solve the problem here, I created a function that return a value from reverting the mouse's Y position...
Vector2 RevertMousePosValue(Vector2 mousePos) {
    Vector2 newMousePos;
    newMousePos.x = mousePos.x;
    newMousePos.y = -mousePos.y + Screen.height;

    return newMousePos;
}

How the function and formula works:

And then applying it in the Update() function:
void Update() {
    Vector2 mousePos = RevertMousePosValue(Input.mousePosition);
}

So, what I do next is to compile all scripts together while switching the "Input.mousePosition" with "mousePos":
using UnityEngine;
using System.Collections;

public class TestingScript : MonoBehaviour {
    private Vector2 mousePos;
    
    void Update() {
        mousePos = RevertMousePosValue(Input.mousePosition);
    }

    void OnGUI() {
        Rect buttonRect = new Rect(20,20,50,50);
        GUI.Button(buttonRect, "");
        if (buttonRect.Contains(mousePos))
        {
            print("haha");
        }
    }
    Vector2 RevertMousePosValue(Vector2 mousePos) {
        Vector2 newMousePos;
        newMousePos.x = mousePos.x;
        newMousePos.y = -mousePos + Screen.height;

        return newMousePos;
    }
}

and... that should do it. Check out my mini coding project which uses similar method.

Saturday, December 18, 2010

Unity3d + C#: Return-able functions in C#

I'm still new to the C# environment, and is working on my first application coded entirely using C#...

So when I was using Java, functions can always be return by simply writing the "return" phrase, followed by the value you want to return:
function ReturnAValue(a,b,c) {
    return a+b+c;
}

But after coding for a while in C#, I realize that I just can't simply put the "return" phrase in a void function (in C# they use "void", instead of "function", really confusing for beginners)... So anyway, I figure out a way to deal with it at the moment. Say you want to return a "float" value in a new function, here's what you do: instead of writing "void", you write "float" follow by the name of the function:
float ReturnFloatValue(float a, float b, float c) {
    return a+b+c;
}


Haven't try other variable types yet, but I guess it's pretty much the same... Will practice more on XNA as soon as I'm done with my current project~

Unity3d + C#: Referencing object's script variables...

Just something I kept forgetting when scripting with C#...

If a variable is not "public static", then it cannot be reference from other script such as this:
//If we are taking a bool variable called "canAccess" from another script called "Player.cs"...
Player.canAccess = true;

Thus, in order to reference a variable from a script which is not "public static", first, you need to state the script name as the class of the variable, follow by the name of the variable:
Player playerScript = 

Then, after the equal sign, "cast the variable", before stating the "GetComponent" function:
//"obj" is the game object which you want to access to...
Player playerScript = (Player)obj.gameObject.GetComponent("Player");
//Now you can reference the variable...
playerScript.canAccess = true;

It's kinda long, and I always forgot about the "casting" part...