Showing posts with label Coding. Show all posts
Showing posts with label Coding. Show all posts

Tuesday, 14 May 2013

End Game

Here I will be describing the problems we had with our final instalment of vertical slice of our game Dionysus below you can see the first person controller facing outside the house pod. The added in the fog to hide the rendering of the trees as you can see where crossovers are this position of one of the parts and as you can see it is not their. This will be shown once the plant in front has been eaten also below you can see in the bottom right-hand corner. There is the mini map that Alistair made, which shows the position of the controller with red arrow.



below is a closer up image of previous few above, and their health by the top left-hand corner has also got smaller as decreases over time due to your hunger.


one of our main problems was that when you first eat one of the plants. The mini map will disappear forever and will not return. We looked into this and could not find a solution, even though the mini map was successful and worked well due to perhaps encoding it just disappears.and also, as you can see from the plants being eaten apart are described earlier, has now appeared.


below is the pause menu that cat made using the coding as shown on the blog . Unfortunately, due to the lock of the mouse and not coding the buttons to do their own functions. It doesn't work that this show that we were on the verge of finishing it and we needed more time to code


below is a video showing the character, leaving the part eating the plant, seeing the object to pick up and picks it up. This is just shows the basics and the core mechanic of our game.


Problems:
  • Getting the code to work for the health and death zones around Alistairs trees
  • to get the mini map to stay on the screen after plants being eaten
  • getting the pause menu to work
  • having an end game screen or reverting back to menu
Overview:

looking at the vertical slice. We believe that the core mechanic has been shown due to hallucinations from eating the plant to finding a part to the fix your ship. This is the core mechanic of Dionysus . We believe, for the first vertical slice. We have made. This is a great combination of all our knowledge and special skills and a unique talents from Alistair JJ, who mainly focused on 3-D and Alice and Cat who focused on coding and Rebecca, focusing on 2-D. The team had its ups and downs, but overall the vertical slice has come out to be a solid game yet you do not have a death screen and an endgame, but as I said above, the core mechanic of the game has been shown using this knowledge that we have learnt the game that we will make in the third year will be greater than this vertical size due to the knowledge lessons we have learned and all help us a lot in the future

Thanks for your help. Tanguay, Steve and Robin


AI Information code pontentially working

using UnityEngine;
using System.Collections;
public class Information : MonoBehaviour {
 // Use this for initialization
 void Start () {

 }

 // Update is called once per frame
 void Update () {

 }


// This function checks if the player has entered a trigger
 void OnTriggerEnter(Collider other)
 {
  // The switch statement checks what tag the other gameobject is, and reacts accordingly.
  switch(other.gameObject.tag)
  {
   case "FlowerInfo":
   hitObj.gameObject.BroadcastMessage("This plant seems to have healing capabilities");
   break;
  
      case "LeavingDoor":
   hitObj.gameObject.BroadcastMessage("Hello Comrade, you are missing parts for your distress beacon, search the canyon for this parts");
            break;
  
      case "DeathSpot":
      hitObj.gameObject.BroadcastMessage("Comrade, this area appears to be very damaging towards your health");
   break;
  
  
       }
 }
}

Pause Menu code

using UnityEngine;

using System.Collections;

public class PauseMenu1 : MonoBehaviour

{

public GUISkin myskin;

private Rect windowRect;

private bool paused = false, waited = true;



private void Start ()

{

windowRect =
new Rect(Screen.width /2 -100, Screen.height /2 -100, 200, 200);

}





private void Waiting()

{

waited =
true;

}



private void Update()

{

if(Input.GetKey (KeyCode.Escape) || Input.GetKey (KeyCode.P))

{

if (paused)

paused=false;

else

paused =true;



waited =
false;



Invoke(
"Waiting", 0.3f);

}



if(paused)



Time.timeScale = 0;



else



Time.timeScale = 1;





}









private void OnGUI()

{

if(paused)

windowRect = GUI.Window(0, windowRect, windowFunct, "Pause Menu");

}



private void windowFunct(int id)

{

if(GUILayout.Button("Resume"))

{

paused =
false;

}



if(GUILayout.Button("Options"))

{



}



if(GUILayout.Button ("Quit Game"))

{



}

}

}

Health Damage and Health Bar Code


public class HealthBar : MonoBehaviour
{
 //  player's health and health bar
 public float curHP=100;
 public float maxHP=100;
 public float maxBAR=100;
 public float HealthBarLength;


 void OnGUI()
 {
  //  creates the health bar at the coordinates 10,10
  GUI.Box(new Rect(10,10,HealthBarLength,25), "");
  //  determines the length of the health bar
  HealthBarLength=curHP*maxBAR/maxHP;
 }

 void ChangeHP(float Change)
 {
  //  takes whatever value is passed to this function and add it to curHP.
  curHP+=Change;

  // This if statement ensures we don't go over the max health
  if(curHP>maxHP)
  {
   curHP=100;
  }

  // This if statement is to check if the player has died
  if(curHP<=0)
  {
   // Die
   Debug.Log("Player has died!");
  }
 }

 // This function checks if the player has entered a trigger
 void OnTriggerEnter(Collider other)
 {
  // The switch statement checks what tag the other gameobject is, and reacts accordingly.
  switch(other.gameObject.tag)
  {
  case "Heal":
   ChangeHP(5);
   break;
  case "Damage":
   ChangeHP(-25);
   break;
  }
  // Finally, this line destroys the gameObject the player collided with.
  Destroy(other.gameObject);
 }
}


Now we just need to add a timer which Alice is currently looking into :)

using UnityEngine;
using System.Collections;

public class HealthBar : MonoBehaviour
{
 //  player's health and health bar
 public float curHP=100;
 public float maxHP=100;
 public float maxBAR=100;
 public float HealthBarLength;
 private float updateDisplayTime = 0F;


 void Start()
 {
   updateDisplayTime = Time.time + 5F;
 }

 void Update()
 {

        if ( updateDisplayTime < Time.time )
     
   {
         curHP -= 3;
         updateDisplayTime = Time.time + 5F;
   }

    if ( curHP <= 0 )
      {
          this.enabled = false;
      }
 }
 void OnGUI()
 {
  //  creates the health bar at the coordinates 10,10
  GUI.Box(new Rect(10,10,HealthBarLength,25), "");
  //  determines the length of the health bar
  HealthBarLength=curHP*maxBAR/maxHP;
 }

 void ChangeHP(float Change)
 {
  //  takes whatever value is passed to this function and add it to curHP.
  curHP+=Change;

  // This if statement ensures we don't go over the max health
  if(curHP>maxHP)
  {
   curHP=100;
  }

  // This if statement is to check if the player has died
  if(curHP<=0)
  {
   // Die
   Debug.Log("Player has died!");
  }
 }

 // This function checks if the player has entered a trigger
 void OnTriggerEnter(Collider other)
 {
  // The switch statement checks what tag the other gameobject is, and reacts accordingly.
  switch(other.gameObject.tag)
  {

  case "Heal":
   ChangeHP(5);
   break;
  case "Damage":
   ChangeHP(-1);
   break;

   if ( updateDisplayTime < Time.time )
    
  {
        curHP -= 10;
        updateDisplayTime = Time.time + 5F;
  }

   if ( curHP <= 0 )
     {
         this.enabled = false;
     }

  }
  // Finally, this line destroys the gameObject the player collided with.
  Destroy(other.gameObject);
 }
}


The "private float updateDisplayTime = 0F;" we managed to find from one of Alisters lessons, so that there is a counter to how quickly the health decreases when you're near the trees.

Monday, 13 May 2013

Crosshair, Fog and Code

 
Using these codes below I got the mouse to stay in the center of the screen
 
These codes are Javer Script and there in yellow
 
Code 1:: function Update () {
    Screen.lockCursor = true;
    Screen.lockCursor = false;
}
 
Code 2:: Screen.showCursor = false;
 
 
Also to get the crosshair to show in the center of the screen I uead this code.
 
Crosshair Code:
 
Code 3: var crosshairTexture : Texture2D;
var position : Rect;
static var OriginalOn = true;
function Start()
 {
  position = Rect((Screen.width - crosshairTexture.width) / 2, (Screen.height -
  crosshairTexture.height) /2, crosshairTexture.width, crosshairTexture.height);
 
 }
function OnGUI()
 {
 if(OriginalOn == true)
 {
  GUI.DrawTexture(position, crosshairTexture);
 }
}

 
Below is the crosshair that I made in Photoshop and then added to unity.
 
 
 
Using the simple reder settings (see Below) we added fog so we could hide the trees when they redered. 
 
 

Friday, 10 May 2013

Update


Alistair has added a crosshair so that the mouse locks in at the centre of the screen and made assets

JJ has edited sound effects and made assets

Alice has added a health bar, but we are having problems trying to get it so the health gradually decreases, goes up on eating a fruit and goes down on being near the tree's dealing damage or in the water.

I have added extra lighting to the pod and other areas like the AI and cave. Edited the waterfall texture so its showing water falling instead of a spray effect. I found some more sounds and added them to the game however only the ones attached to the first person controller are currently working and we'll need to add the door and eating effects to the code. Added in the assets JJ and Alistair made. Added code for a pause menu but it doesn't completely work with our current code/properly.

Play a sound on Click code

I've found two codes where you click an object and a sound will play:

System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"c:\mywavfile.wav"); < change this part to whatever sound we want
player.Play();



 
private void Button_Click(object sender, EventArgs e)
{
using (var soundPlayer = new SoundPlayer(@"c:\Windows\Media\chimes.wav")) {
soundPlayer.Play(); // can also use soundPlayer.PlaySync()
}
}


 

Health Bar Code

    using UnityEngine;
          using System.Collections;
 
public class PlayerHealth : MonoBehaviour {
 
public int maxHealth = 100;
public int curHealth = 100;
 
public float healthBarLength;
 
// Use this for initialization
void Start () {
 
healthBarLength = Screen.width /2;
 
}
// Update is called once per frame
void Update () {
AddjustCurrentHealth(0); 
void OnGUI(){
 
GUI.Box (new Rect(10,10, healthBarLength, 20), curHealth + "/" + maxHealth);
 
}
 
 
public void AddjustCurrentHealth(int adj)
 
{
 
curHealth += adj;
 
if(curHealth <0)
curHealth = 0; 
 
if(curHealth > maxHealth)
curHealth = maxHealth;
 
if(maxHealth <1)
maxHealth = 1;
 
healthBarLength =(Screen.width /2) * (curHealth / (float)maxHealth);
 }
}
 
I put this code in and the health bar is being shown in the top left hand corner of the screen. I am having trouble at the moment getting it to decrease everytime you go near Alisairs tree's or if you go in the water. It probably needs an if, else statement, Cat when your are next in i'll show you what happens and you might be able to help me get it to work :- )

Yeah the unityanswers this code came from doesnt have any solutions I doubt we are actually going to get this to work

Thursday, 2 May 2013

Following AI code update

Hope we have fixed the ai circling bug with this snippet of code.
if we change this part of the previous code

//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;

to:


//move towards the player if not too close

if ( ( myTransform.position - target.position ).sqrMagnitude > 4F )
{

myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;

}
 
it should only move towards the player if the player is a certain distance away so it should in theory stop moving all together if it is so many units close to the player.

Wednesday, 1 May 2013

ColourFilterControl script


public var cameraNormal : GameObject;
public var cameraRed : GameObject;
public var cameraBlue : GameObject;
public var cameraOrange : GameObject;
public var SWITCH_TO_NORMAL_CAMERA_TIME : float = 10;
public class ColorFilterControl extends MonoBehaviour
{
 public static var Instance : ColorFilterControl = null;
 public function SwitchToRedCamera()
 {
  CancelInvoke("SwitchToNormalCamera");
 
  cameraNormal.SetActive(false);
  cameraRed.SetActive(true);
  cameraBlue.SetActive(false);
  cameraOrange.SetActive(false);
 
  Invoke("SwitchToNormalCamera", SWITCH_TO_NORMAL_CAMERA_TIME );
 }

 public function SwitchToBlueCamera()
 {
  CancelInvoke("SwitchToNormalCamera");
 
  cameraNormal.SetActive(false);
  cameraRed.SetActive(false);
  cameraBlue.SetActive(true);
  cameraOrange.SetActive(false);
 
  Invoke("SwitchToNormalCamera", SWITCH_TO_NORMAL_CAMERA_TIME );
 }

 public function SwitchToOrangeCamera()
 {
  CancelInvoke("SwitchToNormalCamera");
 
  cameraNormal.SetActive(false);
  cameraRed.SetActive(false);
  cameraBlue.SetActive(false);
  cameraOrange.SetActive(true);
 
  Invoke("SwitchToNormalCamera", SWITCH_TO_NORMAL_CAMERA_TIME );
 }

 public function SwitchToNormalCamera()
 {
  cameraNormal.SetActive(true);
  cameraRed.SetActive(false);
  cameraBlue.SetActive(false);
  cameraOrange.SetActive(false);
 }


 function Awake()
 {
  if ( Instance != null )
  {
   Destroy (this );
  }
  else
  {
   Instance = this;
  }

 }

 function Start ()
 {
  SwitchToNormalCamera();
 }

}

PickUp fruit - initiate effect code


#pragma strict
public enum ColorFilterType { normal, red, blue, orange };
public var colorSwitcher : ColorFilterType;
function OnTriggerEnter (other : Collider)
{
 renderer.enabled = false;

 switch ( colorSwitcher )
 {
  case ColorFilterType.normal:
 
   ColorFilterControl.Instance.SwitchToNormalCamera();
   break;
  
  case ColorFilterType.red:
 
   ColorFilterControl.Instance.SwitchToRedCamera();
   break;
  case ColorFilterType.blue:
 
   ColorFilterControl.Instance.SwitchToBlueCamera();
   break;
  
  case ColorFilterType.orange:
 
   ColorFilterControl.Instance.SwitchToOrangeCamera();
   break;  
 }
 
 yield WaitForSeconds (8);
 renderer.enabled = true;
}
/*function update();
{
 if (renderer.enabled = false)
*/

Monday, 29 April 2013

Beacon pickup / rotate code

using UnityEngine;
using System.Collections;
public class Pickup : MonoBehaviour {
 // Use this for initialization
 void Start () {

 }

 public float rotationSpeed = 100.0f;
 // Update is called once per frame
 void Update () {
 transform.Rotate(new Vector3 (0,rotationSpeed * Time.deltaTime, 0));
 }

 void OnTriggerEnter(Collider col){
 if(col.gameObject.tag == "Player"){
   col.gameObject.SendMessage("CellPickup");
   Destroy(gameObject);
  }
}
}

Friday, 26 April 2013

Light/ Colour Script

using UnityEngine;
using System.Collections;

public class DoorControl : MonoBehaviour {

 public bool toggleDoor = false;

 private bool doorOpen = false;
 private const string strOpen = "Open";
 private const string strClose = "Close";

 public TextMesh counterTM;
 private int counter = 0;

 public Light redLight;
 public Light blueLight;
 public Light greenLight;
 public Light orangeLight;

 public int currentCycleState = NONE;
 public float nextCycleTime = 0f;
 public bool enableCyclingOfLights = false;

 //public int countTo4 = 0;

 // Use this for initialization
 void Start () {

 }

 // Update is called once per frame
 void Update ()
 {

  if ( enableCyclingOfLights )
  {
   if ( nextCycleTime < Time.time )
  
   {
   CycleEachLight();
  
   }
  }


  else if (toggleDoor)
  {
   doorOpen = !doorOpen;
 
   if (doorOpen)
   {
    animation.Play(strOpen);
    counter++;
    counterTM.text = counter.ToString ();
  
    // when door is opened and the counter changes
    // check if the lights need to be changed
    UpdateLightsStates( counter );

   }
   else
   {
    animation.Play(strClose);
    counterTM.text = "Closing Door";
   }

   toggleDoor = false;
 
  }
 }

 void CycleEachLight()
 {

  switch ( currentCycleState )
  {
   case NONE:
    SwitchLightOn ( RED );
    currentCycleState = RED;
    nextCycleTime = Time.time + 2f;
    break;
 
   case RED:
    SwitchLightOn ( ORANGE );
    currentCycleState = ORANGE;
    nextCycleTime = Time.time + 2f;
    break;
 
   case ORANGE:
    SwitchLightOn ( GREEN );
    currentCycleState = GREEN;
    nextCycleTime = Time.time + 2f;
    break;
 
   case GREEN:
    SwitchLightOn ( BLUE );
    currentCycleState = BLUE;
    nextCycleTime = Time.time + 2f;
    break;
 
   case BLUE:
    currentCycleState = NONE;
    enableCyclingOfLights = false;
    counter = 0;
    break;
 
 
  }


 }

 void UpdateLightsStates ( int count )
 {
  switch ( count )
  {
   case 2:
    SwitchLightOn ( RED );
    break;
 
   case 4:
    SwitchLightOn ( ORANGE );
    break;
 
   case 7:
    SwitchLightOn ( GREEN );
    break;
 
   case 9:
    SwitchLightOn ( BLUE );
    break;
 
   case 10:
    enableCyclingOfLights = true;
 
    break;
  }



 }

 private const int NONE = 0;
 private const int RED = 1;
 private const int ORANGE = 2;
 private const int GREEN = 3;
 private const int BLUE = 4;


 void SwitchLightOn( int lightToSwitchOn )
 {
  switch ( lightToSwitchOn )
  {
   case RED:
    redLight.enabled = true;
    orangeLight.enabled = false;
    greenLight.enabled = false;
    blueLight.enabled = false;
    break;
 
   case ORANGE:
    orangeLight.enabled = true;
    redLight.enabled = false;
    greenLight.enabled = false;
    blueLight.enabled = false;
    break;
 
   case GREEN:
    greenLight.enabled = true;
    orangeLight.enabled = false;
    redLight.enabled = false;
    blueLight.enabled = false;
    break;
 
   case BLUE:
    blueLight.enabled = true;
    greenLight.enabled = false;
    orangeLight.enabled = false;
    redLight.enabled = false;
    break;
 
 
 
  default:
   //catch all condition
   blueLight.enabled = false;
   greenLight.enabled = false;
   orangeLight.enabled = false;
   redLight.enabled = false;
   break;
 
  }

 }

}

Here is some code Toop and I were thinking of using to make the scene change colour. When you hit the plant, it will make everything that colour.

Monday, 22 April 2013

Possible sound code ?

Hey I know we haven't talked about this butu i thought a possible effect could be once you pick up a plant the beacon component will appear with an invisible collider and using this code:

function OnTriggerEnter(otherObj: Collider){
    if (otherObj.tag == "Player"){
        audio.Play();
    }
}

function OnTriggerExit(otherObj: Collider){
    if (otherObj.tag == "Player"){
        audio.Stop();
    }
}


we could have a sketchy noise pollution type track play whenever you enter the invisble collider I'm trying to work out if i can make it fade in and out kind of thing so i will update if i do. Found this whilst looking for effects stuff

Possible colour correction effect code?

using UnityEngine;
using System.Collections;

public class EffectsList : MonoBehaviour

{

public ColorCorrectionCurves[] arrayOfColorCorrectionCurves;




public GameObject mainCameraObject;




void Start()


{

arrayOfColorCorrectionCurves = mainCameraObject.GetComponentsInChildren<ColorCorrectionCurves>();



}

}


Friday, 19 April 2013

Respawn Plant Script

#pragma strict

function OnTriggerEnter (other : Collider)
{


 renderer.enabled = false;
yield WaitForSeconds (8);
renderer.enabled = true;

}

Here is the script so that when you encounter the box collider the plant will disappear for 8 seconds and the re-appear.

Tuesday, 16 April 2013

Possible Following A.I. code?

 I found this on UnityAnswers, its originally for an enemy to follow player but it doesn't have any triggers in it its simply the following aspect of the script. It's Java.

  1. var target : Transform; //the target
  2. var moveSpeed = 3;
  3. var rotationSpeed = 3; //speed of turning
  4.  
  5. var myTransform : Transform; //current transform data of A.I.
  6.  
  7. function Awake()
  8. {
  9. myTransform = transform;
  10. }
  11.  
  12. function Start()
  13. {
  14. target = GameObject.FindWithTag("Player").transform; //target the player
  15.  
  16. }
  17.  
  18. function Update () {
  19. //rotate to look at the player
  20. myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
  21. Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
  22.  
  23. //move towards the player
  24. myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
  25.  
  26.  
  27. } from what I can gather so long as we have the firstperson camera tagged player (which i think it is) we attach this code to the A.I. and it should follow no matter how far away the player is. Also this was on UnifyCommunity wiki. .http://wiki.unity3d.com/index.php/Flocking

Wednesday, 27 March 2013

Picking Up Stuff Script!

using UnityEngine;
using System.Collections;
public class PickupObject : MonoBehaviour
{

 public int distanceToTestFor = 10;
 private int foodLayerMask = 1 << 8;  // food layer is on 8, so create a bitmask
 private Vector3 OFF_SCREEN_POSITION = new Vector3(0, -100, 0 );

 // Use this for initialization
 void Start () {

 }

 // Update is called once per frame
 void Update ()
 {
  RaycastHit hit;

  if ( Input.GetMouseButtonDown( 0 ) )
  {
   // cast a ray from the current screen position into the game world
   // to test if it hits an object that we can pick up
 
   if ( Physics.Raycast(Camera.main.ScreenPointToRay( Input.mousePosition ),out hit, distanceToTestFor, foodLayerMask ))
   {
//    hit.transform.position = OFF_SCREEN_POSITION; - this is only needed if you want to respawn the food
//    hit.transform.gameObject.SendMessage("Respawn");
  
    Destroy( gameObject );
   }
 
  }

 }

}

This is the script to be able to actually click on the food (plants) and be able to pick them up. We could use the pool of objects manager script from our coding lessons to respawn the food, but with this code, we will only be able to have lots of food sources which will then be "destroyed" when clicked on.  

I have put up the excersise we did in the coding session today on Dropbox, called excersise10.2, hopefully you will be able to see what we did with all the codes and that.

Friday, 22 March 2013

Green Fog for Underwater Script

using UnityEngine;
using System.Collections;

public class Underwater : MonoBehaviour {

 //This script enables underwater effects. Attach to main camera.

    //Define variable
    public int underwaterLevel = 1064;

    //The scene's default fog settings
    private bool defaultFog = RenderSettings.fog;
    private Color defaultFogColor = RenderSettings.fogColor;
    private float defaultFogDensity = RenderSettings.fogDensity;
    private Material defaultSkybox = RenderSettings.skybox;
   

    void Start () {
     //Set the background color
     camera.backgroundColor = new Color(0.70f, 200, 0.15f, 70);
    }

    void Update () {
        if (transform.position.y < underwaterLevel)
        {
            RenderSettings.fog = true;
            RenderSettings.fogColor = new Color(0.70f, 200, 0.15f, 70);  < This is where we have changed the colour.

            RenderSettings.fogDensity = 0.2f;  < This is where we have changed the density
           
        }
        else
        {
            RenderSettings.fog = defaultFog;
            RenderSettings.fogColor = defaultFogColor;
            RenderSettings.fogDensity = defaultFogDensity;
          
        }
    }
}

Thursday, 21 March 2013

Underwater Script

using UnityEngine;
using System.Collections;

public class Underwater : MonoBehaviour {

//This script enables underwater effects.     //Define variable
    public int underwaterLevel = 1064;

    //The scene's default fog settings
    private bool defaultFog = RenderSettings.fog;
    private Color defaultFogColor = RenderSettings.fogColor;
    private float defaultFogDensity = RenderSettings.fogDensity;
    private Material defaultSkybox = RenderSettings.skybox;

    void Start () {
    //Set the background color
    camera.backgroundColor = new Color(0, 0.4f, 0.7f, 1);
    }

    void Update () {
        if (transform.position.y < underwaterLevel)
        {
            RenderSettings.fog = true;
            RenderSettings.fogColor = new Color(0, 0.4f, 0.7f, 0.6f);
            RenderSettings.fogDensity = 0.04f;
          
        }
        else
        {
            RenderSettings.fog = defaultFog;
            RenderSettings.fogColor = defaultFogColor;
            RenderSettings.fogDensity = defaultFogDensity;
          
        }
    }
}


This is the script we have used for the underwater effect. We have added it to the main camera.