Tuesday, August 31, 2010

Week 8

Since I'm no longer in programming anymore, I joined the animation team. I've done a death animation. I've also concepted out some banners, logos, icons etc for marketing.



Tuesday, August 24, 2010

Week 7

When I open up the project folder I worked in class at home, I noticed that the buttons were spaced differently. When I played the game at max screen, the buttons during the pause menu suddenly crunch into each other. I don’t know whats wrong but tried tweaking the numbers and spacing variables a bit and it either spaced it too much or made it worst. I then realized the problem was the way I set up the buttons, do not scale probably with different resolution. If I test it out while the game window is small, it’ll look different when I play it on max screen. So the only other solution I could think of is using layouts.

GUILayout.BeginArea ();
GUILayout.EndArea ();

So implementing the script would be:

Function OnGUI ()
{

GUILayout.BeginArea();

If (GUILayout.Button(“Button 1”)
{
Print(“this button works”);
}
}

The difference with guilayout is that the buttons within the layout are clustered and organized nicely. If you apply a skin or style to the layout, it should affect everything within the layout, in theory or just the layout itself. This is how the gui.button would look like.

Function OnGUI()
{
If(Get.Button(Rect (0,0,0,0)))
{
Print(“this works also”)
}
}

Adding styles to the buttons within the layout was a bit tricky. I faced problems like warp/stretched buttons. I thought it would be the button so I kept tweaking the variable for button dimensions but it would not work the way I want after a few tries. I also had cases where only one button would show up , the rest or all will disappear, overstretch off to one end of the screen and all the other buttons will overlap. At first I think the layout box would be too small, so I tried enlarging the layout so all the buttons will be visible. I could only made the stretching worst. However, what baffle me the most is the first button did not have any negative effects from the new scripts.


function OnGUI()
{

if(Input.GetKey(KeyCode.Escape))
{
paused = true;
print("paused");
}


if(paused == true && startPrompt == true)
{

GUILayout.BeginArea (Rect(Screen.width/2 - 50, Screen.height/2 - 200, 1500, 1500));
Time.timeScale = 0.0;

GUILayout.Button("Menu", menu);

if(GUILayout.Button("Continue", continueStyle))
{
paused = false;
Time.timeScale = 1.0;
}

if(GUILayout.Button("Option", optionStyle))
{
print("This is Option Bitch!");
}

if(GUILayout.Button("redblue", redBlueStyle1))
{
varSwitch = 1;

if(switching == false && varSwitch == 1)
{
switching = true;
varSwitch = 0;
print("switching");
}

if(switching == true && varSwitch == 1)
{
switching = false;
varSwitch = 0;
print("not switching");
}

/*var toggleBoolNew = GUI.Toggle (Rect (25, 25, 100, 30), toggleBool, "Toggle");

// Check if the toggle was toggled
if (toggleBoolNew != toggleBool)
{
if (toggleBoolNew == true)
{
print("Toggle On");
}
else
{
print("Toggle off");
}
}*/
}

if(GUILayout.Button("A", aStyle))
{
print("die!!");
}

if(GUILayout.Button("B", bStyle))
{
print("B works");
}

GUILayout.EndArea ();
}


}


I couldn’t figure out why its stretching the buttons. I spent some times messing with various of variables with no positive results. I then noticed that the buttons been stretched way off to the side. So I look over my script carefully and wondered if the layout size is causing my button to stretch, which I don’t know why it would. So from here I changed the width of the layout to the buttonWidth.

function OnGUI()
{

if(Input.GetKey(KeyCode.Escape))
{
paused = true;
print("paused");
}


if(paused == true && startPrompt == true)
{

GUILayout.BeginArea (Rect(Screen.width/2 - 50, Screen.height/2 - 200, buttonWidth, 1500));


now the width of the buttons is corrected and looks good. from here, I added the box filter for the background and added texture to them.

Tuesday, August 17, 2010

Week 5

The hardest part of this assignment is finding out how to put textures onto the button. A lot of tutorials and help I found online only talking about taking fonts or placing watermark on objects. The problem with that is, I don’t know how to make the object toggle on and off and appear directly on the screen. Using the function OnGui was much simpler when doing that. First solution I came across was playing text textures onto the object .

First thing you have to do is create a gui text. Aligned it to the object that you want the text to be placed on and then child it to the object. From here you basically use a OnMouse function for it to do various things.

Function OnMouseEnter()
{
Renderer.material.color = Color.green;
}

When the player places his mouse over the text, it will turn it green.

Function OnMouseDown()
{
Renderer.material.color = color. red;
}

When the player clicks the text, it turns red. Basically all these mouse states can be used to assign various actions to them. However, returning back to what I had to do, the problem still remain… how am I going to get the buttons show up on cue and in the camera face in their set positions. I tried coming up of different ways of doing it and I tried messing around with GUISkins. I don’t even know where to start with this. I applied it to an object and I don’t know what else to do with it at first. There was a bunch of options to mess around with. I then found the option to apply texture to it. Using the png that I have created, I inserted into the texture slot. Took me a bit to figure out how to apply the skin into the script but reading the reference thoroughly, I was able to do so.

Var guiSkin : GUISkin;

Function OnGui
{
GUI.skin = guiSkin;

Now every gui button created after this will use the skin. To turn it off or to stop the gui you have to null it.

GUILayout.Button(“TESTESTESTETSET”);

GUI.skin = null;
}

Buttons created after the null will now use the default skin instead of the guiSkin. At first I think finding this was great and I began to apply it right away then I realized that I have to apply the guiskin and null for every single button. Making the script very long and redundant. After researching for awhile, I then came across guiStyles.

With guiStyles, you can have every button use the style within the script line and that would save you several lines of code. So after setting up several guiStyles and inserting the png, it looks like something like this.

private var buttonWidth:int = 125;
private var buttonHeight:int = 50;
private var spacing:int = 100;

static var paused = false;
static var startPrompt = false;

var continueStyle : GUIStyle;
var optionStyle : GUIStyle;
var redBlueStyle1 : GUIStyle;
var redBlueStyle2 : GUIStyle;
var aStyle : GUIStyle;
var bStyle : GUIStyle;

var switching = false;


function OnGUI()
{


if(Input.GetKey(KeyCode.Escape))
{
paused = true;
print("paused");


}
if(paused == true && startPrompt == true)
{
Time.timeScale = 0.0;

if(GUI.Button(Rect(Screen.width/2 - buttonWidth/2, Screen.height/2.50 - buttonHeight/2 - spacing, buttonWidth, buttonHeight),"Continue", continueStyle))
{
paused = false;
Time.timeScale = 1.0;
}
if(GUI.Button(Rect(Screen.width/2 - buttonWidth/2, Screen.height/2.15 - buttonHeight/2 - spacing, buttonWidth, buttonHeight),"Option", optionStyle))
{
print("This is Option Bitch!");
}
if(GUI.Button(Rect(Screen.width/2 - buttonWidth/2, Screen.height/1.9- buttonHeight/2 - spacing, buttonWidth, buttonHeight),"redblue", redBlueStyle1))
{
varSwitch = 1;

if(switching == false && varSwitch == 1)
{
switching = true;
varSwitch = 0;
print("switching");
}

if(switching == true && varSwitch == 1)
{
switching = false;
varSwitch = 0;
print("not switching");
}

}
if(GUI.Button(Rect(Screen.width/2 - buttonWidth/2, Screen.height/1.70 - buttonHeight/2 - spacing, buttonWidth, buttonHeight),"A", aStyle))
{
print("die!!");
}
if(GUI.Button(Rect(Screen.width/2 - buttonWidth/2, Screen.height/1.5 - buttonHeight/2 - spacing, buttonWidth, buttonHeight),"B", bStyle))
{
print("B works");
}
}
}

I wanted to try using GUILayouts. I haven’t spend much time with it but there were a few errors where the button wouldn’t show up but the text or the none of the parameters would work. I might have to tinker with it some more. Using GUILayouts, it organize the buttons nicely so you don’t have to fiddle around too much with aligning the buttons.

One of the other things I tried to do is getting the gui toggle to work. Gui toggle work with a Bool.

var toggleBool = true;

function OnGui()
{
var toggleBoolNew = GUI.Toggle (Rect (25, 25, 100, 30), toggleBool, "Toggle");

// Check if the toggle was toggled
if (toggleBoolNew != toggleBool)
{
if (toggleBoolNew == true)
{
print("Toggle On");
}
else
{
print("Toggle off");
}
}
}

This script was able to place a toggle at the top left corner and you can click it to toggle but when I placed it in the button, I couldn’t get it to work. I’m not sure whats the problem. I haven’t messed around with bools enough to figure it out atm.


For Marketing, I've came up with 2 poster ideas and slightly rendered them.






The first concept is having the head with the eye of horus, reaching out to grab the jar which contains remnants of osiris in it. The second picture is a portrait of horus in his falcon form. I wanted to make him hard to see because we aren't releasing character design/concept yet. I made his eye glow to symbolize his powers.

And I came up with 3 teaser quotes that we could use on the poster or other advertising materials.

- Events that shook the very foundation of his life that it’ll never be the same again.
- In a race against time to set things right.
- Don’t think you’ll get away that easily.

Tuesday, August 10, 2010

Week 4

Alex wanted me to create a gui that comes up when the game starts and prompt the user what he wanted to use: keyboard/mouse or xbox controller. When that is fleshed out, he wants to be able to hit a key that will pause the game with a menu that has a button that will let him continue the game. I researched on how to create a gui and found resources on using unity to create buttons to us for the gui for the time being. To use the gui in unity, all gui must be under the

function OnGUI()
{
}

The function OnGUI() works like function Update() so it will keep checking the script every frame. The gui script im using functions like

GUI.Button(shape(position), "text"))

In the example that was shown to me youtube, the position was determined by division of the screen. So if you divide the screen in half:

GUI.Button(Rect(Screen.width/2 - buttonWidth/2, Screen.height/2 - buttonHeight/2 - spacing, buttonWidth, buttonHeight), "text")

it should place the button in the middle of the screen. I needed two buttons that are able to set joystick variable accordingly. Only way to do this is to have the script call the variable from the player script and set it. So I immediately changed the var joyStick to a static var joyStick. Now the other scripts can call that script and made changes.

The tutorial showed how to make the button clickable so we could add if/else statements in them. Just simply add if in the beginning and place a bracket around everything else.

if(GUI.Button(Rect(Screen.width/3 - buttonWidth/2, Screen.height/2 - buttonHeight/2 - spacing, buttonWidth, buttonHeight), "Keyboard/Mouse"))

this should let me be able to click it. So I created a startPrompt script to show up immediately when the game start.


Function OnGui()

{
if(GUI.Button(Rect(Screen.width/3 - buttonWidth/2, Screen.height/2 - buttonHeight/2 - spacing, buttonWidth, buttonHeight), "Keyboard/Mouse"))

}


Now I need to add the statements. Alex wanted the script to be able to set the joystick to either keyboard/mouse or xbox controller. So having already set the joystick to static in the playerControl script, I need to add a statement and create another IF statement.


private var buttonWidth:int = 125;
private var buttonHeight:int = 50;
private var spacing:int = 100;

Function OnGUI()
{
if(GUI.Button(Rect(Screen.width/3 - buttonWidth/2, Screen.height/2 - buttonHeight/2 - spacing, buttonWidth, buttonHeight), "Keyboard/Mouse"))
{

PlayerControls.joyStick = 0;
Destroy(this);

}


if(GUI.Button(Rect(Screen.width/3 - buttonWidth/2, Screen.height/2 - buttonHeight/2 - spacing, buttonWidth, buttonHeight), "Keyboard/Mouse"))
{

PlayerControls.joyStick = 1;
Destroy(this);
}

So now when the game start, it will prompt the user with 2 buttons. One will set the joystick controls to keyboard/mouse, the other to the xbox controller. I added the destroy in the script so it will end it when the player decide on controls. Otherwise the player will constantly be prompt. The private var is there to define the dimension of the button because we used it in the script.The next problem I ran into is the game isn’t paused and you’re still able to do everything else. I found a timescale script that could reduce game speed down to 0, stopping everything from playing or something of that nature. The script also needed to be the first thing to work before everything else. Using the timescale, I was able to freeze the game(pause) and wait for the player to pick controls and then continue(this is where the destroy script helps make this function work the way I want). First I wanted the game to stop so I placed the timescale at the top of the script in the OnGUI function.


private var buttonWidth:int = 125;
private var buttonHeight:int = 50;
private var spacing:int = 100;

Function OnGUI()
{
Time.timeScale = 0.0;

if(GUI.Button(Rect(Screen.width/3 - buttonWidth/2, Screen.height/2 - buttonHeight/2 - spacing, buttonWidth, buttonHeight), "Keyboard/Mouse"))
{

PlayerControls.joyStick = 0;
Time.timeScale = 1.0;
Destroy(this);

}
if(GUI.Button(Rect(Screen.width/3 - buttonWidth/2, Screen.height/2 - buttonHeight/2 - spacing, buttonWidth, buttonHeight), "Keyboard/Mouse"))
{

PlayerControls.joyStick = 1;
Time.timeScale = 1.0;
Destroy(this);
}
}


With the timescale in place, it will pause immediately then prompt with the two buttons. The numbers used to divide the screen will position the buttons so they don’t overlap each other. Now I have to set up an input key so it pauses in the game, pop up a menu button that allows the player to continue the game. I looked up on key inputs and the script that looked best to use is Input.GetKey(KeyCode.key) key is which key you want to set it up to use as input. Theres a list that showed which could be used.


private var buttonWidth:int = 125;
private var buttonHeight:int = 50;
private var spacing:int = 100;

static var paused = false;

function OnGUI()
{
If(Input.GetKey(KeyCode.Escape))
{
Paused = true;
Print(“paused”);
Time.timeScale = 0.0;
}
If(paused == true)
{
Time.timeScale = 0.0;

if(GUI.Button(Rect(Screen.width/2 - buttonWidth/2, Screen.height/2 - buttonHeight/2 - spacing, buttonWidth, buttonHeight), "Continue"))
{
Paused = false;
Time.timeScale = 1.0;
}
}
}

It should pause the game when you hit escape the script would set paused to true and trigger the if statement to bring up the button. After testing a few times, I noticed when I hit the escape during the startprompt the ingame pause function would come up. I have to set up a variable for the menu script to only work if the startprompt is done.


private var buttonWidth:int = 125;
private var buttonHeight:int = 50;
private var spacing:int = 100;

static var paused = false;
static var startPrompt = false

function OnGUI()
{

If(Input.GetKey(KeyCode.Escape))
{
Paused = true;
Print(“paused”);
Time.timeScale = 0.0;
}
If(paused == true && startPrompt == true)
{
Time.timeScale = 0.0;

if(GUI.Button(Rect(Screen.width/2 - buttonWidth/2, Screen.height/2 - buttonHeight/2 - spacing, buttonWidth, buttonHeight), "Continue"))
{
Paused = false;
Time.timeScale = 1.0;
}
}
}

In the startprompt script, I added the startprompt line to each button if statement to be set to true when one of the controls is picked. The only thing I didnt do was set a joystick input to bring up menu in game because i dont have a controller to test. After testing a few times, the ingame pause menu doen’st show up when you’re still deciding on controller but it still shows up after the controls are pick if you press the escape during the control pick. So the timescale itself is not a true pause. I need to find a real pause function that stops other scripts from doing anything.

Tuesday, August 3, 2010

Week 3

I created a flow chart for the two enemy script alex asked me to do. When touched by a weapon(shape like a stick), one minion will have its head pop off and the other will disappear and be replaced with items.

The scene is set up with a 2 box(player and enemy). Player will have a stick while the enemy will have a head. My first problem I ran into was learning how to get the collider to work. Which was hard because no one knew what every part of the collider script do so I figured out what can general used for set it up with the enemy. Problem is, I don't know how to script an actual collision script or contactPpoint script. After mind numbing reading and researching, OnTrigger script seem to work best if not easiest for me.

After I set up a collider box for the enemy, I inputed

function OnTriggerEnter (other : Collider) {

if (other.gameObject.tag == "weapon") {

print ("hit")

}

}

That script above will print out "hit" in the debug log so I know it works. Now I have to script the head so it will pick up the hit.

function Update (){

if (playerHit == true){

rigidbody.transform.Translate(Vector3.up * 10 * Time.deltaTime);

}

}

If didn't make the head pop and I couldn't figure out why. I realized the problem was the player hit that the collider script is picking up, isn't being picked up by the head script. I couldn't figured it out right away but I found out that I have to make the variable able to be picked up from other scripts. I ran across a script where someone was using static var so I hope that was it

static var playerHit = false;

that still didn't work. I realized after reading the console that I have to specify where the variable is coming from

in the collider script

function OnTriggerEnter (other : Collider) {

if (other.gameObject.tag == "weapon") {

print ("hit")

enemyHead.playerHit = true;

}

}

In this script I have to state that the playerHit is from the enemyHead script.

With those scripts in place, everything works except the head won't stop floating. I tried adjusting the gravity but ended up messing with the game physics and everything was affected by it. Spent hours on unity3d and no one could pin point the problem or how to work with the gravity specifically for the object. It then occur to me that the jump script in the fps walker does exactly what I needed. I asked Robin if he could help me created and we both looked over the walker script to see what we can learn from it. Robin came up with a script for me that didn't work for me for some reason so I used and wrote my own script from what I learned and able to get the head to pop up and drop. Now the problem is it bounces up and down, non stop.

I added

private var moveDirection = Vector3.zero;

and placed

moveDirection.y -= gravity * Time.deltaTime;

in the update function. this script will need refining for it to work smoothly.

Now I have the enemy replace, item drop script to work on. I used most of the same scene and some of the scripts with some modification. Now understanding how to do this is easy, knowing the scripts to use is a whole different story. Based on my past experience with Unity Script, I have to instantiate an object with the object I want to replace. Prefabbing which was easy.

Same problem I had with the gravity script and moving script, no where tells you the exact function of every part of the script so you know what needs to be replaced and so on.

After researching for an hour, I learned that when instantiating, you will need to var the objects you want to make reference to.

var object1 : GameObject

var object2 : GameObject

*I've seen some put Transform instead of game object with im baffled about.

the instantiate script is

Instantiate(object you want to create, object you want to replace(transform), object you want to replace rotation(rotation);

that script should instantiate for you.

I created a script and collider for the body. With my new understanding how instantiate works.

I set the body script to instantiate the prefab in its location and then destroy itself, revealing the drop item.

var poops : GameObject;

var enemy : gameObject;

function OnTriggerEnter (other : Collider){

if (other.gameObject.tag == "weapon"){

Instantiate(poops, enemy.transform.position, enemy.transform.rotation);

Destroy(enemy);

}

}

And that script should work.

Week 2

I am in charge of working on the minion script. My task was to get the minion flying, hover around the character, and be able to maneuver. It has been awhile that I actually sat down and scripted in unity so it took me some time to figure out what scripts was needed.

I started by using the FPS walker script that has been prefab’d in unity.

-------------------------------

var speed = 6.0;

var jumpSpeed = 8.0;

var gravity = 20.0;

private var moveDirection = Vector3.zero;

private var grounded : boolean = false;

function FixedUpdate() {

if (grounded) {

// We are grounded, so recalculate movedirection directly from axes

moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

moveDirection = transform.TransformDirection(moveDirection);

moveDirection *= speed;

if (Input.GetButton ("Jump")) {

moveDirection.y = jumpSpeed;

}

}

// Apply gravity

moveDirection.y -= gravity * Time.deltaTime;

// Move the controller

var controller : CharacterController = GetComponent(CharacterController);

var flags = controller.Move(moveDirection * Time.deltaTime);

grounded = (flags & CollisionFlags.CollidedBelow) != 0;

}

@script RequireComponent(CharacterController)

----------------------------------

As I was trying to read the script, I had to look up on what some of functions were doing like FixedUpdate() which I found out that its like the regular FixedUpdate but should only be used for rigid bodies. for what the bodies starts adding force, it will count/update for every fixed frame of it.

To simplify the character controller script to use for the minion. I established the keyboard speed with var keyboardSpeed = 50; testing the script at this speed was too fast so I brought it down to 1.

From there I added function

FixedUpdate()

{

Var keyboardX = Input.GetAxis(“Horizontal”) * keyboardSpeed * Time.deltaTime;

//The script line above stats the default settings for moving on the X axis is set to default keys and run on the set keyboard speed and smoothly per frame. I completed with the rest of the moving lines:

Var keyboardZ = Input.GetAxis(“Vertical”) * keyboardSpeed * Time.deltaTime;

Var keyboardY = Input.GetKey(“Space”) * keyboardSpeed * Time.deltaTime;

//The jump script above had to be set to the default jump settings until I can figure out a more specific and manual way of scripting the jump. The script line for jump didn’t work and I had to figure out a fix which I did later.

var newPos = rigidbody.position + Vector3(keyboardX, keyboardY, keyboardZ);

//take the current rigidbody position + the changed(added) axis changes from key inputs = newPos

rigidbody.MovePosition(newPos);

//take the newPos coordinates and move the rigidbody to that location

}

@script RequireComponent(Rigidbody)

I used unity3d to look up script and reference.

The jump was tricky for me to get working and I wasn’t completely sure if we were going to use the jump but I figured I could always mod the script later to do a ascend and descend. The jump had to set its y variable and assigned an input. I couldn’t get it right, right away. I was getting a input script error for that script line. After talking to rob about it, he told me about the default jump that’s in unity.

I just had to add a variable at the top

Var Jump

Then change

Input.GetKey(“Space”)

To

Input.GetAxis(“Jump”)

Jump is the default setting for jump in unity and it works for now but the gravity is applied to the character which restricts the floating/hovering that Alex wants.

Week 1

I didn’t do any programming. I just did research on things from the list: animals, basket, design (motif, patterns etc), some general stuff, monuments, plants, pottery, some rituals, statues, tools and weapons. Searching for stuff like plants and animals was difficult because you have to find out the name for most of them in order to get more result for them. Tools was spread out. There were tools for crafting, farming, rituals and so on.