Thursday, April 19, 2012

Final Project


Our final project is online at:

http://www.prism.gatech.edu/~ksheffield3/LCC_2730_FINAL_PROJECT_QUIDDITCH/WebPlayer/WebPlayer.html

As far as my role in the final project, I was the main scripter and also the assembler. I wrote the scripts for broom movement, snitch movement, hand reaching, winning and losing, scene navigation, and GUI creation. I put all of the assets into scenes, put the intro scene into the main project from a different project, as well as tweaking cameras and objects to increase playabilitiy and feel. I controlled a lot of the camera's and lighting. I set up all collisions and triggers. These were my scripts:

Snitch Movement:


using UnityEngine;
using System.Collections;

public class SnitchMove : MonoBehaviour
{
public int speed = 5;

public int height;

public Vector3 centerOfBase;
public float a;
public float b;

private Vector3 move;
private float durationCounter;

void Start()
{
do
{
durationCounter = Random.value * 3;
move = Random.insideUnitSphere.normalized * speed * durationCounter;
}while(!Validate());
}

void Update()
{
if(durationCounter > 0)
{
transform.Translate(move*Time.deltaTime);
durationCounter -= Time.deltaTime;
}
if(durationCounter <= 0)
{
do
{
durationCounter = Random.value * 3;
move = Random.insideUnitSphere.normalized * speed * durationCounter;
}while(!Validate());

}
}

bool Validate()
{
float yPos = transform.position.y + durationCounter * move.y;
if(yPos < centerOfBase.y || yPos > centerOfBase.y + height)
{
return false;
}
float A = transform.position.z + durationCounter * move.z - centerOfBase.z;
float B = transform.position.x + durationCounter * move.x - centerOfBase.x;
return( (Mathf.Pow(A, 2)/Mathf.Pow(a, 2)) + (Mathf.Pow(B, 2)/Mathf.Pow(b, 2)) <= 1 );
}

void OnTriggerEnter(Collider obj)
{
if(obj.gameObject.name == "Hand" && GameObject.Find ("Player").GetComponent<ReachHand>().IsReaching())
{
gameObject.GetComponent<MeshCollider>().isTrigger = false;
GameObject.Find("Player").GetComponent<BroomstickMove>().enabled = false;
gameObject.GetComponent<TrailRenderer>().enabled = false;
gameObject.transform.parent = GameObject.Find("Hand").transform;
GameObject.Find("Player").GetComponent<ReachHand>().Win();
enabled = false;
}
}
}

Broomstick Movement



using UnityEngine;
using System.Collections;

public class BroomstickMove : MonoBehaviour
{
public float speed = 20;
public float accelerationModifier = 80;

public int pitchSensitivity = 2;
public int rollSensitivity = 5;
public int yawSensitivity = 3;

void Start()
{

}

void Update()
{
transform.Translate(Vector3.forward*speed*Time.deltaTime);
CheckForInput();
}

void CheckForInput()
{
if(Input.GetKey("a"))
{
transform.Rotate(0,-pitchSensitivity,0);
}
if(Input.GetKey("d"))
{
transform.Rotate(0,pitchSensitivity,0);
}
if(Input.GetKey("q"))
{
transform.Rotate(0,0,yawSensitivity);
}
if(Input.GetKey("e"))
{
transform.Rotate(0,0,-yawSensitivity);
}
if(Input.GetKey("w"))
{
transform.Rotate(rollSensitivity,0,0);
}
if(Input.GetKey("s"))
{
transform.Rotate(-rollSensitivity,0,0);
}
if(Input.GetKeyDown("space"))
{
speed += accelerationModifier;
}
if(Input.GetKeyUp("space"))
{
speed -= accelerationModifier;
}
if(Input.GetKeyUp("r"))
{
gameObject.GetComponent<ReachHand>().Reach(Vector3.left);
}
}
}

Reach Hand Out and Grab Snitch

using UnityEngine;
using System.Collections;

public class ReachHand : MonoBehaviour
{
public GameObject hand;
public float maxDuration = 2;
public float speed = 2;
private Vector3 direction;
private bool reaching = false;
private float durationCounter = 0;
private bool win = false;
void Start()
{
}
void Update()
{
if(reaching)
{
hand.transform.Translate(speed * direction * Time.deltaTime);
durationCounter += Time.deltaTime;
if(durationCounter >= maxDuration)
{
reaching = false;
}
}
else if(!reaching && durationCounter > 0)
{
hand.transform.Translate(speed * -direction * Time.deltaTime);
durationCounter -= Time.deltaTime;
}
if(durationCounter <= 0 && win)
{
Application.LoadLevel("WinScreen");
}
}
public void Reach(Vector3 direction)
{
if(!reaching && durationCounter <= 0)
{
reaching = true;
this.direction = direction;
}
}
public bool IsReaching()
{
return (durationCounter > 0);
}
public void Win()
{
maxDuration = durationCounter;
win = true;
}
}

Lose If You Collide with Terrain

using UnityEngine;
using System.Collections;

public class CollideTerrain : MonoBehaviour
{

void Start()
{
}
void Update()
{
}
void OnTriggerEnter(Collider obj)
{
if(obj.gameObject.name == "BroomCollide")
{
Application.LoadLevel("LoseScreen");
}
}
}

A Couple GUI Scripts

using UnityEngine;
using System.Collections;

public class PlayAgain : MonoBehaviour
{
public string buttonText;
void Start()
{
}
void Update()
{
}
void OnGUI()
{
Rect buttonRect1 = new Rect(Screen.width / 3, 7 * Screen.height / 9, Screen.width / 3, Screen.height / 9);
GUIContent buttonContent1 = new GUIContent(buttonText);
if(GUI.Button(buttonRect1, buttonContent1))
{
Application.LoadLevel("StartScreen");
}
}
}

using UnityEngine;
using System.Collections;

public class ToIntro : MonoBehaviour
{
void Start()
{
}
void Update()
{
}
void OnGUI()
{
Rect buttonRect1 = new Rect(Screen.width / 3, 2 * Screen.height / 7, Screen.width / 3, Screen.height / 7);
GUIContent buttonContent1 = new GUIContent("Start");
if(GUI.Button(buttonRect1, buttonContent1))
{
Application.LoadLevel("IntroScreen");
}
Rect buttonRect2 = new Rect(Screen.width / 3, 4 * Screen.height / 7, Screen.width / 3, Screen.height / 7);
GUIContent buttonContent2 = new GUIContent("Instructions");
if(GUI.Button(buttonRect2, buttonContent2))
{
Application.LoadLevel("InstructionScreen");
}
}
}

using UnityEngine;
using System.Collections;

public class BackToMenu : MonoBehaviour
{
void Start()
{
}
void Update()
{
}
void OnGUI()
{
Rect buttonRect1 = new Rect(Screen.width / 3, 13 * Screen.height / 15, Screen.width / 3, Screen.height / 15);
GUIContent buttonContent1 = new GUIContent("Back");
if(GUI.Button(buttonRect1, buttonContent1))
{
Application.LoadLevel("StartScreen");
}
}
}

All of my scripts were written in C#. I had a few issues that required major debug time. The bigger one is that trigger's are bugged in unity, and don't work quite the way they're supposed to. This was an issue when I tried to use a cylinder as the bounding box for my snitch. Upon realizing there was not easy fix to the bug, I changed my code completely to be done mathematically. Additionally, I hit a bug where two mesh colliders won't collide, so used some creative collider use to compensate. I think I played a major role in this project and that it came out very well.


Tuesday, April 10, 2012

Readings and Project Progress

Readings


Laurel
The Laurel reading talked about computer programming and interaction, and how they were a form of performance. I don't really agree with this. I feel as if Laurel uses too broad a definition for performance, which allows for this claim to be made. Laurel also oversimplifies the ideas of programming. If programmers were actors, why then wouldn't you also consider actors to include writers, painters, or even athletes? The argument seems like a bit of a stretch..

Phelan
Phelan discusses the validity of performance in still art in the narrative of the observers. With all due respect to Phelan, this concept is a stretch. While some pieces of still art may inspire greater conversation than others, simply inspiring conversation is not enough to validate performance. If I were to have a conversation with a peer about chocolate, chocolate wouldn't become a performance. The concept is ridiculous.

Progress


So far I have adjust and implemented my flight script for the broomstick and made significant progress in the snitch move script.