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:
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.
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.
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.
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.
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.
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
Leave a Reply