Week 4 - Particles/Lighting plus smoothing animations

As we were moving closer towards our deadline for assignment introduced during workshop number 2, there were still some important elements left to implement in our small gaming project called Unity-Chan. These are as following: Multiple Lights, Particles/Particle System, Audio (background music and effects) and animations other than character animations (optional).

Particle System

Upon our group discussion, we have decided that the best spot, where to put our particle system and what effect it should have is a sparkling effect added between the two swinging hammers from the ceiling which hit each other and therefore a collision occurs which would create such effect.

The sparking was created based on the following tutorials provided by Unity but also Youtube Unity enthusiasts
      - https://unity3d.com/learn/tutorials/topics/graphics/particle-system?playlist=17102
      - https://www.youtube.com/watch?v=MYU1vBcUkfw
      - https://www.youtube.com/watch?v=0NCTAuP3BgU

Creating a particle system was more about fiddling with setting in Unity than programming an actual script in C# which would handle the behaviour for us.

Below you can see a Unity screenshot which ilustrates the settings of our particles effect.


As you can see there are numerous preferences that you can play around with. I am going to mention only the most important ones which were relevant for us.

 Duration - Duration was set up to the smallest possible value, what is 0.05 as the effect is happening only during the collision of two objects which is a small amount of time.

 Looping - Checked off as we do not want to shoot sparkles indifinetely but based on certain condition.

Velocity over Lifetime - Linear Z axis was set up to value -4, as this value determined into which direction are sparkles being shooted, because we wanted them fly away from the collision.

Color over Lifetime - The color of a particle is changing gradiently as we can see at the picture to add more relistic effect.

Lights - Each particle is actually also considered as a source of light, therefore it also helps to brighten the space and makes it look more natural.

Texture - It is also important to remind that each particle contains a texture of a small glowing point light with Shader setting being set to "Particles/Additive".

The list of setting goes on and on, obviously but as I mentioned earlier, these were the most essential ones.

Of course, it was necessary to create and edit a C# script attached to one of the hammers to control a specific behaviour depending on the conditions that we set up named "Collision Right Hammer". Below you can see a script attached to the game object also containing a field called "Effect" which is of type Particle System.



Now, lets take a look on the script more in depth below.


As you can see, the only thing it took was to create a public variable, which I have described earlier and initialize pre-defined method called "OnCollisionEnter", which describes what is going to happen on collision of one of our hammers. Our sparkling effect will be played according to predefined settings of Particle System in Unity inspector window.

The picture below represents what it looks like, once everything was finished.


Audio (background music and effects)

After discussion in our team, we decided to add sound for jump animation, and some sound for background.
For jump animation we wrote the following script:



As you can observe, we created two public variables:
*AudioSource - a representation of audio sources in 3D.
*AudioClip - a container for audio data.
In Update method, we used a "if" statement to check if the button for jumping is pressed, and in this case, if button is pressed, we declare that AudioSource.clip is equal for jumping. And in the next step we just used the method play, to set on the sound, of course only for jumping.

After that, we set up the the jumping field with the sound, and source field with the game object:



For the background music we set up the Audio Source component for the main camera:



For playing the music in endless cycle, we activated the loop.

Comments