Final
Video Player is loading.
Current Time 0:00
Duration -:-
Loaded: 0%
Stream Type LIVE
Remaining Time -:-
 
1x
    • Chapters
    • descriptions off, selected
    • captions off, selected

       

      Screen Shot 2016-03-09 at 12.43.25 AM Screen Shot 2016-03-09 at 12.43.18 AM Screen Shot 2016-03-09 at 12.43.32 AM Screen Shot 2016-03-09 at 12.43.50 AMScreen Shot 2016-03-09 at 12.43.39 AM

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      GitHub Link

      Adding The Final Touches
      I had planned to use a special glass breaking assets package, however when I went to use this, it had been updated to work with the latest unity edition. Just in case it would effect my game, I kept the edition I had been working with and searched for new assets. I found Glass Pack. I can use these 3D models and use my own imported sounds to try to hack the code.

      Back in the Game Engine

      I started out by changing the box collider to a mesh collider on the chair.

      I imported the assets package and pulled in one of the models/prefabs. The prefabs and models seemed to work exactly the same. I played with size and placement. Compared to the 3D objects, these models needed a bit more sizing up, regarding scale.

      After adding the rigid body and mesh collider, the glass would not move when hit. So i tested with box collider, edited the size of the collider and it worked.

      Here is a basic step by step for pulling in each glass:
      1) Add glass
      2) Adjust scale and location
      3) Add rigid body
      4) Change mass
      5) Add box collider
      6) Edit Size
      7) Test

      Once I added a bunch of glassware, I played the game to see if the box colliders of the glassware were interacting with each other, and cleaned that up a bit by rearranging the glass objects.

      ADDING SOUND
      From here I added the background music (Italian-American ambience), by dropping the sound into the hierarchy.

      Now comes the part where I may have to head into C# to make sounds happened on specific cues.

      The sound goals:
      Glass Tap – Noise made when hands hit glass
      Glass Break – Noise made when glass his the bottom plane (the floor)

      I went to our code that we used for the pong game, when adding sound to the ball when it hit the paddles and thought to explore this particular code, along with the other code from that script ball.cs:

       void Start () {
              rb = GetComponent<Rigidbody2D> ();
              rb.velocity = Vector2.right * speed;
              //takig that value and timesing it by the speed
              snd = GetComponent<AudioSource> ();
          }

      I hacked the code in C# to this:

      using UnityEngine.SceneManagement;
      public class GlassTap : MonoBehaviour {
      public float speed = 30;
      //declaring sound variable
      private AudioSource snd;
      //declaring rigid body
      private Rigidbody rb;
      //not quite sure what this does
      private Transform trans;
      // Use this for initialization
      void Start () {
      //call rigid body
      rb = GetComponent<Rigidbody> ();
      //not quite sure how this grabs speed and uses it
      rb.velocity = Vector3.right * speed;
      //get sound
      snd = GetComponent <AudioSource> ();
      //I believe this calls the action on this particular object
      trans = this.transform;
      }
      //ask the sound to play on collision with the HandController
      void OnCollisionEnter3D(Collision col){
      if (col.gameObject.name == "HandController") {
      float y = calculatePosition (transform.position, col.transform.position, col.collider.bounds.size.y);
      Vector3 direction = new Vector3 (1, y).normalized;
      rb.velocity = direction * speed;
      snd.Play ();
      }
      }
      }

      However, this did not work. I don’t know C# and my java script knowledge base at this point does not allow me the ability to trouble shoot this code as a programmer would. (Please note, I am not a programmer, and I have only had one semester of creative coding with P5.js, a form of Java Script, so code is really like learning a new language. If this were in Japanese, I would have no problem.)

      So instead, my plan is to work through some unity tutorials on collision.

      After testing this tutorial, it looks like I do not need the “collision”  option, rather I need to code for the “collider” component.

      This Unity tutorial showed me basic code for enacting a one-time sound upon collision.

      This help section mentioned what else besides code needs to be set.
      Add box collider to HandController
      Set that collider as trigger

      I then added the ping sound and C# code to the HandController to test if the code works with the other parameters in place. I pressed play and unity froze. But when I finally did get it to play, the ping noise did not work on command with the script.

      I tried making the glass itself the trigger, and that actually made the glass fall right through the table, despite the rigid body of the table.

      I found this great, easy to understand, straight forward video tutorial, and the script would not work at all in this version of Unity.  Lesson Learned!

      I found two separate scripts (1, 2) that I combined to make a working script. In the first example, audio.Play();  would not work without calling the component, so together they came.

      //https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/audio
      //http://docs.unity3d.com/ScriptReference/AudioSource.Play.html
      using UnityEngine;
      using System.Collections;
      public class pingScript : MonoBehaviour {
      //Volume: 0-1
      //Magnitude: volume dependent on magnitude
      // Use this for initialization
      //defines what happens when something hits the cube/the cube hits something
      void OnCollisionEnter (Collision col)
      {
      AudioSource audio = GetComponent<AudioSource> ();
      audio.Play ();
      }
      }

       

      For some reason there is a ping happening right off the bat when the game runs, so I need to explore why that is happening – it was burried in one of the objects in the hierarchy – so I removed it along with an old script.  – And the sound was suddenly very strange, beeping pings non-stop, even though this was not happening before.

      And then unity froze again.

      But it turns out the sound was just on Loop. Un-clicked that, the looping stopped, but the initial ping still happened without any collision – and on Awake was not clicked. I wonder if it has to do with the placement of the object on the table, hitting immediately upon the sketch starting. The reason—> no matter how the glass object is placed on the table object, it “collides” with the table, so the sound is played immediately. I tried removing the sound from the glasses and having it be triggered by the HandController, but that did not work. It definitely has to do with the placement on the table and colliding right from the start.

      I tried aligning the glass objects to the table object and found that it shows to sit exactly on top at Position: Y: 88.51. I set all of the glass objects to this.

      I finally reached out to a fella at ITP who has well versed in the ways of Unity and he was able to share this code and explain it to me.

      //https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/audio
      //http://docs.unity3d.com/ScriptReference/AudioSource.Play.html
      //AV 'Sehyun Kim'
      using UnityEngine;
      using System.Collections;
      public class pingScript : MonoBehaviour {
      //create boolean terms
      bool isStartedMoving;
      //declare vector 3 to control x y z axes
      Vector3 pos, pre_pos;
      void Start(){
      //boolean is false
      isStartedMoving = false;
      //pos = transform position set in unity
      pos = transform.position;
      //pre_pos = same as above pos
      pre_pos = transform.position;
      }
      void Update(){
      //pos is the current transform position
      pos = transform.position;
      //if pos.x and pre_pos.x do NOT equal each other, boolean is true, else it is not
      if (pos.x != pre_pos.x) {
      isStartedMoving = true;
      } else {
      isStartedMoving = false;
      }
      //Debug.Log (isStartedMoving);
      //pre_pos takes on the value of pos
      pre_pos = pos;
      //basically the first time through pos and pre_pos will be false so this will not do anything - the next times through they will not be equal, the boolean will evaluate to true and the code below will enable the audio to play on collision
      }
      //defines what happens when something hits the cube/the cube hits something
      void OnCollisionEnter (Collision col) {
      AudioSource audio = GetComponent<AudioSource> ();
      //play only when isStartedMoving is true - see above
      if (isStartedMoving) {
      audio.Play ();
      }
      }
      }

       

       

      I quickly jumped to the glass breaking sound for when the glasses crash onto the floor. I added the sound of the crash script to the Floor plane object and it worked perfectly.

      //https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/audio
      //http://docs.unity3d.com/ScriptReference/AudioSource.Play.html
      using UnityEngine;
      using System.Collections;
      public class crash : MonoBehaviour {
      //create collision function
      void OnCollisionEnter (Collision col)
      {
      //call audio source by getting component
      AudioSource audio = GetComponent<AudioSource> ();
      //play audio
      audio.Play ();
      }
      }

      Finally, I created a new scene for the start menu, and much like I did with my pong game, I added an opening screen with a start button.

      Screen Shot 2016-03-09 at 12.53.47 AM

      However, when I run the game through this start screen, the colors of scene are a bit darker, and one wall is completely black. Not exactly sure where this is coming from. But the game can be run with or without that start screen.
      Screen Shot 2016-03-09 at 12.43.10 AMScreen Shot 2016-03-09 at 12.53.55 AM

       

       

       

      So here we have my first interactive 3D Unity game, Mano Italiano

      Assets:
      Music – Come Prima, Tony Reno
      Leap Motion Assets
      Furniture
      Glassware
      Dishes
      Plates
      Photos – personal archives
      Code –
      http://pixelnest.io/tutorials/2d-game-unity/menus/
      http://docs.unity3d.com/ScriptReference/AudioSource.Play.html
      https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/audio
      Sehyun ‘AV’ Kim
      https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/audio
      http://docs.unity3d.com/ScriptReference/AudioSource.Play.html

      // Reference: http://pixelnest.io/tutorials/2d-game-unity/menus/
      using UnityEngine;
      using System.Collections;
      public class start : MonoBehaviour {
      // Use this for initialization
      void OnGUI () {
      const int buttonWidth = 200;
      const int buttonHeight = 30;
      //determine the button's place on screen
      Rect buttonRect = new Rect (
      Screen.width / 2 - (buttonWidth / 2),
      (2 * Screen.height / 4) - (buttonHeight / 2),
      buttonWidth,
      buttonHeight
      );
      //draw a button to start the game
      if (GUI.Button(buttonRect, "Mano Italiano"))
      {
      Application.LoadLevel("Assignment3");
      }
      }
      }