Wednesday, 26 March 2014

Fences

I have now added wooden fences along the path around the game level to help guide the player. I did this due to feedback on my game during the demo day. Many found it difficult to stick to the path due to the visibility of the path and the indifferent terrain throughout. I have tested the new paths with the fence and this problem has now been rectified.

Starting area boundaries

Due to feedback from the demo day of my game, I have added in rocks the guide the player towards the path as shown:


Saturday, 22 March 2014

House interior images

Below are images of the interior of the in game house showing the hallway and all six rooms. I was planning to do a video walk through but the game play was lagging so I decided not to just for now.

Hallway

Room 1 with overturned chair and table

Room 2 with a table, chair and two collectables

Room 3 with a lamp, chest of drawers and another collectable

Room 4 with bloodstained bed and a lamp

Room 5 with bed blocking doorway

Room 6 with an 'operating table' a saw and a blood stained floor

House exterior images

Below are images of the exterior of the house in game that was made in 3Ds Max:



3Ds Max house

I made one of the main assests of the game using 3Ds Max. This was my first time using this software so hopefully it turned out o.k.

Creation of the house:



More updates to come

I will be uploading more content to this blog about the games progress, this will including picture and/ or video content of the game.

Xbox removal

I have decided to remove the Xbox controller and revert back to keyboard and mouse.I have done this because I am constantly changing from a Windows system to a Mac system. Due to the fact that the mapping of the controller changes for each system it results in issues.

Collectable (same for all collectables with different variable names)

public class Collectable2 : MonoBehaviour {

public GameObject Collectable;

public float Distance = 5.0f;

void OnMouseDown()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;

if (Input.GetMouseButtonDown(0) && Vector3.Distance(playerPos, transform.position) <= Distance)
{
HUD.CollectablePoints += 100;
Destroy (gameObject);
HUD.PickUpTextCollectable2 = "";
}
}

void Update()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;

if (Vector3.Distance (playerPos, transform.position) <= Distance)
{
HUD.PickUpTextCollectable2 = "Left Click To Pick Up Book";
}

else
{
HUD.PickUpTextCollectable2 = "";
}

}

}

Enemy movement due to player interaction

public class WindowWalker : MonoBehaviour {

public AudioClip HeartBeat;
// this is an object, so that you can move it around in the editor.
public Transform target;
public GameObject collect;
//public GameObject enemy;

// units per second
public float speed = 3;

//void Start()
//{
// gameObject.renderer.enabled = false;
//}

void Update(){

//if (collect != false)
//{
// gameObject.renderer.enabled = false;
//}

if (collect != true)
{
audio.PlayOneShot(HeartBeat, 1.0f);
//gameObject.renderer.enabled = true;
//spawn = (GameObject)Instantiate(Resources.Load("DarkEnemy"));
// remember, 10 - 5 is 5, so target - position is always your direction.
Vector3 dir = target.position - transform.position;

// magnitude is the total length of a vector.

// getting the magnitude of the direction gives us the amount left to move

float dist = dir.magnitude;

// this makes the length of dir 1 so that you can multiply by it.

dir = -dir.normalized;

// the amount we can move this frame

float move = speed * Time.deltaTime;

// limit our move to what we can travel.

if (move > dist)

move = dist;

// apply the movement to the object.

transform.Translate (dir * move);

Destroy(gameObject, 6);


}
}

//public GameObject Battery;
//public GameObject Man;
//public GameObject GameObjectA;
//public GameObject GameObjectB;

// Update is called once per frame
//void Update ()
//{
// if (Battery != true)
// {
// Instantiate(Man);
// MoveObject(GameObjectA, GameObjectB);
// Destroy(Man);
// }
//}
}

Well sound effect

public class WellSound : MonoBehaviour {

public AudioClip HeartSound;

void OnTriggerEnter (Collider Well)
{
if (Well.tag == "Player" ) {
audio.PlayOneShot(HeartSound, 1.0f);
}
}
}

Battery sound effect

public class HouseBatteryPickUpSound : MonoBehaviour {
public AudioClip heartBeat;

void OnTriggerEnter(Collider Player)
{
if (Player.tag == "Battery")
{
audio.PlayOneShot(heartBeat, 1.0f);
}
}
}

Helicopter blade spin

public class HelicopterBladeSpin : MonoBehaviour {

// Update is called once per frame
void Update () {
transform.Rotate(Vector3.up * 30);
}
}

Graveyard sound effect

public class GraveyardSound : MonoBehaviour {

public AudioClip graveYard;
// Update is called once per frame
void OnTriggerEnter(Collider Player)
{
if (Player.tag == "Graveyard")
{
audio.PlayOneShot(graveYard, 1.0f);
}
}

void OnTriggerExit (Collider Player)
{
if (Player.tag == "Graveyard")
{
audio.PlayOneShot(graveYard, 0.0f);
}
}
}

Flashlight spawn

public class FlashlightSpawn : MonoBehaviour {
void Start()
{
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
GameObject spawn = (GameObject)Instantiate(Resources.Load("Flashlight"));

spawn.transform.position = new Vector3(x, y, 0);
}
}

}
}

Enabling flare (not currently in use but does work)

//public class FlareEnable : MonoBehaviour {
//
// public static float lightFlareLife = 49;
// public AudioClip soundEffect;
// public Light lightFlare;
// public float flareReductionSpeed = 3.0f;
// public AudioClip soundEffect2;
//
// void Awake()
// {
// lightFlare.enabled = false;
// }
//
// void Update()
// {
// if (HUD.FlareCount > 0)
// {
// lightFlareLife = lightFlareLife - (flareReductionSpeed * Time.deltaTime);
//
// }
//
// if (Input.GetButtonDown ("LeftBumper") && HUD.FlareCount > 0 && !lightFlare.enabled)
// {
// audio.PlayOneShot(soundEffect, 1.0f);
// audio.PlayOneShot(soundEffect2, 1.0f);
//
// if (lightFlareLife <= 0 && HUD.FlareCount > 0)
// {
// lightFlareLife = 0;
// HUD.FlareCount--;
// lightFlareLife = 49;
// }
// lightFlare.enabled = true;
//
// }
//
//
// if (lightFlareLife <= 0)
// {
// lightFlareLife = 0;
// lightFlare.enabled = false;
// }
// }
//}


Enemy spawn

public class enemyVillageSpawn : MonoBehaviour {

//public AudioClip HeartBeat;
public GameObject spawnPoint;

public GameObject collect;

void Update(){

if (collect != true)
{
//audio.PlayOneShot(HeartBeat, 1.0f);
GameObject spawn = (GameObject)Instantiate(Resources.Load("DarkEnemy1"));
Debug.Log("I HAVE SPAWNED");
}


}
}

Enemy following player

public class EnemyFollow : MonoBehaviour {
public Transform target; //will show in inspecter but dont need to fill in
public int moveSpeed;
public int rotationSpeed;
public int maxdistance; //if player within this distance in inspector it will follow is not it will not follow
private Transform myTransform;
public AudioClip approachHeartBeat; //this is sound effect dont need


void Start(){
myTransform = transform;
target = GameObject.FindGameObjectWithTag ("Player").transform;//will find object tagged Player
}

void Update () {
if (Vector3.Distance(target.position, myTransform.position) < maxdistance)
{

//Debug.Log ("I AM FUCKING MOVING");
audio.PlayOneShot(approachHeartBeat, 1.0f); //this is sound effect dont need
// Get a direction vector from us to the target
Vector3 dir = target.position - myTransform.position;

// Normalize it so that it's a unit direction vector
dir.Normalize();

// Move ourselves in that direction
transform.position += dir * moveSpeed * Time.deltaTime;
}

if (Vector3.Distance (target.position, myTransform.position) > maxdistance)
{
Destroy(gameObject);
}

}
}


Flashlight pick up

public class pickUpClick : MonoBehaviour {
//public GameObject SpawnPoint;
public enum Item
{
Flashlight,
}
public float Distance = 5.0f;

public Item item;

void OnMouseDown()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;

if (Input.GetMouseButtonDown(0) && Vector3.Distance(playerPos, transform.position) <= Distance)
{
HUD.HasFlashlight = true;
Destroy (gameObject);
HUD.PickUpTextTorch = "";



//Instantiate(Resources.Load("Flashlight"));//, gameObject.transform.position = playerPos);
//gameObject.transform.position = playerPos;
//SpawnPoint = (GameObject)Instantiate(Resources.Load("Flashlight"));
}
}

void Update()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;

if (Vector3.Distance (playerPos, transform.position) <= Distance )// && HUD.HasFlashlight == false
{
HUD.PickUpTextTorch = "Left Click To Pick Up Flashlight";
}

else
{
HUD.PickUpTextTorch = "";
}

}

// public AudioClip flashlightSound;
// public AudioClip batterySound;
//
// void OnMouseDown()
// {
// var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
//
// if(Input.GetMouseButtonDown(0) && Vector3.Distance(playerPos, transform.position) <= Distance)
// {
// if(item == Item.Flashlight)
// {
// Flashlight.HeadLightMount.SetActiveRecursively(true);
// Flashlight.HeadLightMount.active = true;
//
// AudioSource.PlayClipAtPoint(flashlightSound, transform.position, 1);
//
// HUD.HasFlashlight = true;
// }
// else
// HUD.BatteryCount++;
//
// AudioSource.PlayClipAtPoint(batterySound, transform.position, 1);
//
// Destroy(gameObject);
// }
// }
}

HUD

public class HUD : MonoBehaviour
{
public static double CollectablePoints;
public static string PickUpTextTorch;
//public static int FlareCount;
public static int BatteryCount;
public static bool HasFlashlight;
//public static string PickUpTextFlare;
public static string PickUpTextCollectable1;
public static string PickUpTextCollectable2;
public static string PickUpTextCollectable3;
public static string PickUpTextCollectable4;
public static string PickUpTextCollectable5;
public static string PickUpTextCollectable6;
public static string PickUpTextCollectable7;
public static string PickUpTextBattery;


public void OnGUI()
{
if (HasFlashlight)
{
GUI.Label (new Rect (10, 10, 80, 30), "Flashlight");
GUI.Label (new Rect (70, 10, 80, 30), Flashlight.BatteryLife.ToString ("F2"));
}


GUI.Label (new Rect (10, 40, 80, 30), "Batteries");
GUI.Label (new Rect (70, 40, 80, 30), BatteryCount.ToString ());


//GUI.Label (new Rect (10, 55, 80, 30), "Flares");
//GUI.Label (new Rect (70, 55, 80, 30), FlareCount.ToString ());


GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextTorch.ToString ());

GUI.Label (new Rect (10, 65, 80, 30), "Points");
GUI.Label (new Rect (70, 65, 80, 30), CollectablePoints.ToString ());



GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable1.ToString ());

GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable2.ToString ());

GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable3.ToString ());

GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable4.ToString ());

GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable5.ToString ());

GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable6.ToString ());

GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable7.ToString ());

GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextBattery.ToString ());

//GUI.Label (new Rect (700, 1000, 200, 30), "");
//GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextFlare.ToString ());
}
}

Battery pick up

public class HouseBatteryPickUp : MonoBehaviour {

public float Distance = 5.0f;

public GameObject Battery;

// void OnTriggerEnter(Collider other)
// {
// if (other.tag == "Player") { //&& Input.GetButtonDown("xButton") == true)
// HUD.HasFlashlight = true;
// Destroy (gameObject);
// }
//
//
// }
void OnMouseDown()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;

if (Input.GetMouseButtonDown(0) && Vector3.Distance(playerPos, transform.position) <= Distance)
{
HUD.BatteryCount++;
Destroy(gameObject);
HUD.PickUpTextBattery = "";
}
}


void Update()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;

if (Vector3.Distance (playerPos, transform.position) <= Distance)
{
HUD.PickUpTextBattery = "Left Click To Pick Up Battery";
}

else
{
HUD.PickUpTextBattery = "";
}

}
}

Flashlight script

public class Flashlight : MonoBehaviour {

public static float BatteryLife = 100;
public AudioClip soundEffect;
public Light Torch;
public float BatteryReductionSpeed = 3.0f;

void Awake()
{
Torch.enabled = false;
}

void Update()
{
if (Torch.enabled)
{
BatteryLife = BatteryLife - (BatteryReductionSpeed * Time.deltaTime);

}

if (Input.GetButtonDown ("RightBumper") && HUD.HasFlashlight && !Torch.enabled)
{
audio.PlayOneShot(soundEffect, 1.0f);

if (BatteryLife <= 0 && HUD.BatteryCount>0)
{
HUD.BatteryCount--;
BatteryLife = 100;
}
Torch.enabled = true;
}
else if (Input.GetButtonDown ("RightBumper") && HUD.HasFlashlight && Torch.enabled)
{
audio.PlayOneShot(soundEffect, 1.0f);

Torch.enabled = false;
}

if (BatteryLife <= 0)
{
BatteryLife = 0;
Torch.enabled = false;
}
}
}

Updating scripts

I will now be uploading all scripts that I am currently using, this does not include scripts I have made but are not in use. I have also kept the comments in but these are mostly failed attempts of what I was trying to accomplish, this is for future reference.

Tuesday, 4 March 2014

Xbox 360 Controller Mapping

I have now changed the controls so they work on a Xbox 360 controller. To do this is used the input directory in unity under edit>project setting>input. I changed the names of the controls and buttons in this to match the controller mapping. I used the following site for the names of the controllers buttons for unity. I then changed the code that needed to be changed to get this to work, however for the first person controls on the analogue sticks I had to change no code as the names were fine and worked as expected. One problem I had was that the right analogue stick looking control moved continuously when the stick was moved, to fix this I had to add some 'Dead' to it.

Code changes

The past three coding posts that were uploaded may change. I may change the code in some or all of these scripts to improve the gameplay and make it more efficient. As of now this code is being used to get the basic mechanics of the game working as expected. If I do change any of these scripts I will upload the new code and state what changes have been made.

Flashlight Code

Below is the code for the flashlight, it does the following:


  • Upon spawn the player will not have a flashlight
  • When a flashlight is collected it will be off until it is turned on
  • if the player has a torch and it is on reduce the battery life
  • if the right bumper (xbox controller) is pressed the light will turn on if it not
  • likewise if the right bumper button is pressed when the flashlight is on, it will turn off
  • when the flashlight is collected the HUD for the battery life will be set to 100
  • if the battery life is less than or equal to 0 set it to zero and turn the flashlight off
  • if the battery life is 0 and the HUD shows that batteries are held reduce the battery count by one and add 100 to the battery life (for the flashlight)

using UnityEngine;
using System.Collections;

public class Flashlight : MonoBehaviour {

public static float BatteryLife = 100;

public Light Torch;
public float BatteryReductionSpeed = 3.0f;

void Awake()
{
Torch.enabled = false;
}

void Update()
{
if (Torch.enabled) 
{
BatteryLife = BatteryLife - (BatteryReductionSpeed * Time.deltaTime);

}

if (Input.GetButtonDown ("RightBumper") && HUD.HasFlashlight && !Torch.enabled) 
{
if (BatteryLife <= 0 && HUD.BatteryCount>0)
{
HUD.BatteryCount--;
BatteryLife = 100;
}
Torch.enabled = true;
else if (Input.GetButtonDown ("RightBumper") && HUD.HasFlashlight && Torch.enabled)
{
Torch.enabled = false;
}

if (BatteryLife <= 0) 
{
BatteryLife = 0;
Torch.enabled = false;
}
}
}

Pick Up code

Below is the code for the picking up of the objects such as the torch and batteries. The code for the battery pick up isn't complete yet as there are no batteries in the scene as of yet. The game object i.e the flashlight will be destroyed (taken off the scene) when it has been picked up, as shown in this code. As of yet the object will be picked up when it is simply walked into, I want to improve this so the player is prompted with a button to press to pick up objects.

using UnityEngine;
using System.Collections;

public class PickUp : MonoBehaviour {

public enum Item
{
Flashlight,
Battery
}

public Item item;

void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
HUD.HasFlashlight = true;
Destroy(gameObject);
}

//else
//HUD.BatteryCount++;
//Destroy (gameObject);
}
}

Flashlight HUD

Below is the C# sharp code I used to create the HUD for the flashlight. This code will display the flashlights remaining power out of 100, which will only show when a flashlight is collected, and below the number of batteries held will be shown:

using UnityEngine;
using System.Collections;

public class HUD : MonoBehaviour
{
public static int BatteryCount;
public static bool HasFlashlight;

void OnGUI()
{
if (HasFlashlight)
{
GUI.Label (new Rect (10, 10, 80, 30), "Flashlight");
GUI.Label (new Rect (70, 10, 80, 30), Flashlight.BatteryLife.ToString ("F2"));
}
GUI.Label (new Rect (10, 40, 80, 30), "Batteries");
GUI.Label (new Rect (70, 40, 80, 30), BatteryCount.ToString ());
}
}

Monday, 24 February 2014

Starting level video


This is a video of my starting area in this level:

Main mechanic of enemy following

I have now added the main mechanic of the enemy to follow the player. I got the code from this site but I have added some modifications and fixed errors in the code. This is the code below:



using UnityEngine;
using System.Collections;

public class EnemyFollow : MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
public int maxdistance;
private Transform myTransform;

void Start(){
myTransform = transform;
}

void Update () {
if (Vector3.Distance(target.position, myTransform.position) < maxdistance)
{
// Get a direction vector from us to the target
Vector3 dir = target.position - myTransform.position;

// Normalize it so that it's a unit direction vector
dir.Normalize();

// Move ourselves in that direction
myTransform.position += dir * moveSpeed * Time.deltaTime;
}
}
}




The distance from the player to begin movement of the object and speed of the object can be edited on the right panel of the script as shown below:

Sunday, 23 February 2014

More Trees

I have now added more trees to make the forest type area a lot more dense. Instead of using all the same type of tree I have added colliders to a variety of tree types, the same way as before, and mixed these tree types together across the landscape.

Monday, 17 February 2014

Trello




















I have created a Trello account to keep track of my progress, what I need to do, what I have done, and what I am doing. This helps me organise my project and allows me to see clearly what must be done.


Colliders on the crashed plane


I have now added colliders to the crashed plane so the player can no longer walk through this plane.

I added these colliders to the plane in the same way as I did on the trees in the area. This time I used multiple colliders on the plane to cover it affectively.




Adding spin to propeller

I have added spin the crashed planes broken propeller as an extra feature of the starting area.

Below is the simple C# code I used to add the spin to the propeller:


using UnityEngine;
using System.Collections;

public class Propellerspin : MonoBehaviour {

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
transform.Rotate(Vector3.up * 3);
}
}

Starting Area

I have used multiple planes to create the starting area as I could not separate the parts of the plane to create the area. Therefore I have moved and manipulated the planes to arrange them in the way needed to make it look like a plane crash site. I have also used the particle effects in the unity engine to add fire to the crash site as seen below.


Aircraft

I downloaded an aircraft pack from the Unity asset store. That pack was called "World WarII P47 thunderbolt."

Below is an image of the planes included in the pack:


Adding colliders to trees







To add a collider I selected the tree went to the component menu then to physics and to the collider depending on what shape you require.










A collider will be added as a green outline to the object. This can be resized using the menu to the right. The width, height and position can be changed.









One the collider has been placed, create a prefab, add the tree to the prefab and click apply. You now have a collider to all the trees in this prefab.

Adding Boundaries

I have added boundaries to level in the form of water. The entire island is surrounded by water and at the waters edge I have added invisible walls to prevent the player walking off the edge of the map. I did this by adding empty game objects and placing them around the edge of the map.


Terrain Toolkit

I have created the snowy environment for my level by adding an asset to the project called the 'Terrain Toolkit.' This was used to randomly generate the environment, such as hills, the link for this download is below:

https://code.google.com/p/unityterraintoolkit/downloads/detail?name=Terrain%20Toolkit%201.0.2.zip&can=2&q=

Once downloaded you simply drag the folder into the assets folder of your unity project.
You then add the terrain toolkit component to your terrain.


Here you can see the terrain toolkit component to the right of the screen.

Game Idea

My game takes place on a snowy, hilly, island environment. You play as a crashed aeroplane pilot who has been stranded  on this island. They must get to the evacuation site on the other side of the island where there is a waiting helicopter. Along the way the player must battle dense forest, abandoned buildings, snow storms and creature that are located on the island. The enemies will only attack when the player gets within a certain radius of them or shines the torch they have on the enemy. The player must then run from creatures to escape from them before they are killed.