Showing posts with label game sound. Show all posts
Showing posts with label game sound. Show all posts

Wednesday, October 30, 2013

Using OSC to Control Unity - Simple Demo



I'll be doing a write up on this shortly.







Saturday, October 26, 2013

Unity Sound Example - Simple LFO Modulator

A quick demo that makes use of Mathf.sin(), Update() and a variable to modulate the pitch of an audio asset via an LFO.

In short, the process is:
• Find an in-game object that currently triggers a single sound
• Find the script that is associated with that object that triggers that sound
• Create a variable at the top of the code for indexing the LFO, e.g.:
var LFO_index : float = 0.0; 
• Find or create the update() { } function in the same script
• Add the following code to the update() function:
LFO_index = LFO_index + 0.1;
audio.pitch = 1.0 + (Mathf.Sin(LFO_index) * 0.2);
• In the above two lines of code, changing the value of "0.1" will adjust the speed of the LFO modulator
• In the above two lines of code, changing the value of "0.2" will adjust the depth of the LFO modulator
• In the above two lines of code, the audio.pitch attribute can be changed to something else (e.g. audio.volume etc).


Unity Sound Example - Contiguous File Playback from Event Trigger

This is a quick example showing how the same event trigger can play a different sound asset from an array in order - using a variable, modulo and an AudioClip[] array.

In short:
• Find an in-game object that currently triggers a single sound
• Find the script that is associated with that object that triggers that sound
• Add an AudioClip[] array variable to the top of the code e.g.:
var SoundFileNames : AudioClip[];
• Add a variable to the top of the code for storing the index of the sound file name array e.g.:
var SoundIndex : int = 0;
• Find the audio.Play() function within that script
• Add code above audio.play() that reads:
SoundIndex = (SoundIndex + 1) % SoundFileNames.length;
audio.clip = SoundFileNames[SoundIndex];
• Remember to inspect the object in Unity via the Inspector and populate the audio clip array with audio assets!


Friday, October 25, 2013

Unity Sound Example - Looping, Random Sound Files for Triggered Event

A quick demo that makes use of AudioClip[], audio.loop, audio.isPlaying, update(), and a true / false flag in order to play back a looping array of randomised sounds when an event trigger is activated.

In this example, a single sound source that loops is replaced with an array of sound assets that are randomly played back for every loop.

This example uses the unity 4.x demo "Angrybots". The standard autofire gunshot sound - which loops continuously when the fire button is held down - is replaced with an array of sounds (which could be slightly varied gunshot sounds) and change with every loop.

In short, the process for this particular example is:
• Find an in-game object that currently triggers a single sound that loops continuously
• Find the script that is associated with that object that triggers that sound
• Add an AudioClip[] array variable to the top of the code e.g.:
var RandomSoundNames : AudioClip[];
• Find the audio.play() function within that script
• Add code above audio.play() that reads:
audio.clip = RandomSoundNames[Random.Range(0, RandomSoundNames.length)];
audio.loop = false;

• Find or create the update() { } function in the same script
• Add the following code to the update() function:
if(autofire == true && audio.isPlaying == false) {
audio.clip = RandomSoundNames[Random.Range(0, RandomSoundNames.length)];
audio.play();
}

• Remember to inspect the object in Unity via the Inspector and update the random audio array with audio assets!


Wednesday, October 23, 2013

Unity Sound Example - Random Audio File Playback

A quick demo that makes use of AudioClip[] array, audio.clip and Random.Range() to randomise the audio asset file that is played back when an event is triggered.

In short, the process is:
• Find an in-game object that currently triggers a single sound
• Find the script that is associated with that object that triggers that sound
• Define a new variable at the start of that script to create an array of audio clips,  e.g. var RandomSounds: AudioClip[];
• Find a reference to audio.Play(); within the script
• Randomise the selection of the audio clip in the line before audio.Play(); e.g. audio.clip = RandomSounds[Random.Range(0,RandomSounds.length)];
• Save the script and run the game again


Unity Sound Example - Random Volume

A quick demo that makes use of audio.volume and Random.Range() to randomise the volume of a triggered sound in Unity.

In short, the process is:
• Find an in-game object that currently triggers a single sound
• Find the script that is associated with that object that triggers that sound
• Find a reference to audio.Play(); within the script
• Randomise the volume of the audio source in the line before audio.Play(); e.g. audio.volume = Random.Range(0.1, 1.0);
• Save the script and run the game again
• Note that the parameter of volume is an amplitude multiplier (e.g., 1.0 is 100% amplitude, 0.5 is 50% amplitude etc).



Unity Sound Example - Random Pitch

A quick demo that makes use of audio.pitch and Random.Range() to randomise the pitch of a triggered sound in Unity.

In short, the process is:
• Find an in-game object that currently triggers a single sound
• Find the script that is associated with that object that triggers that sound
• Find a reference to audio.Play(); within the script
• Randomise the pitch of the audio source in the line before audio.Play(); e.g. audio.pitch = Random.Range(0.5, 2.0);
• Save the script and run the game again
• Note that the parameter of pitch is a sound playback rate / ratio value (e.g. 1.0 is normal pitch, 0.5 is half pitch, 2.0 is an octave up etc). 



Wednesday, October 16, 2013

WindGen - Noise Sound Generator M4L Device

Wind noise generator. Can be layered for maximum control.

Download here: http://milkcrate.com.au/_other/downloads/M4L/WindGen.amxd

RainMaker - Random Note Generator M4L Device

A simple random note generator. Useful for generating atmospheric / ambient sound textures.

Download here: http://milkcrate.com.au/_other/downloads/M4L/RainMaker.amxd

Wednesday, August 28, 2013

GameSalad Template Example 4: Replacing Sound Assets

This micro tutorial demonstrates how to easily replace a sound asset.

Many assets can be replaced in a similar fashion.


Drag a new sound into the Audio Library of Game Salad. 


Navigate to a sound within the actor's set of rules and behaviors that  is already associated with an event.


Delete the sound playback behaviour and replace it with the new sound asset by dragging and dropping from the Audio Library. 


Set the volume / pitch as required.



GameSalad Template Example 3: Randomised Sound Assets

The aim of this tutorial is to demonstrate the randomisation of sound events when triggered from one collision. This example includes the random choice of two different sound files but can be easily extended.

 Navigate to Scenes > Scene 1

 Go to the Attributes tab on the left hand side.
 
Create a new attribute with the + button. The attribute should be an integer type. 

Rename the attribute to Random_Number, and make sure the initial value is 0. 

Create a new rule for the main character. 

Set the Rule conditions to Actor receives event > overlaps or collides > with actor of type > InvisiSpring.

 Create another rule.
Set the rule conditions to Attribute, and select the attribute Game > Random_Number. Set the value of Random_Number to 0.  Drag this rule so that it sits within the previous rule.

Drag a sound to the behaviour area of the rule that was created in the previous step. This sound will trigger whenever the random number is equal to 0. 


Copy the rule that was created two steps ago. Set the value of Random_Number to 1 instead of 0. Select a different sound asset. This second sound will trigger whenever the random number is equal to 1. 


Add a new behaviour for Change Attributes from the Behaviour tool box on the left hand side. Select the target attribute for Game > Random_Number and enter an expression using the Random function.

Random(min, max) will appear in the expression box. 


Change this to Random(0, 1). 
Move the Change Attribute(Game.Random_Number >> Random(0, 1)) so that it sits before the first sound playback Rule.


 The following diagram summarises the logic flow of the above Rules and Behaviours:



Tuesday, August 27, 2013

GameSalad Template Example 2: Add Background Music

As per the previous GameSalad Template example, the aim for this example is to add sound to an existing template.

Simply navigate to Scenes > Scene 1 > Platform Character.

Import a sound file that is to be used as background music, by dragging it to the "Sounds" tab.


Select to import as "Music" asset rather than a sound asset.


Create a new rule. Set the conditions to Attribute > Game > Time = 0

GameSalad Template Example 1: Attach Sound Asset to Event

This brief tutorial demonstrates how to attach a sound asset to an event that does not currently have any sound associated with it.

In this example, a new sound is associated with the "spring bounce" event in the Platformer Template project. 


 Create a new project from the templates. Be sure to choose "Platformer Template"


Navigate to the scenes tab.


Open the first scene. 


Double-click on the main platform character.


Click on the sounds tab in the bottom left hand corner. Drag a new sound to the sounds tab.


Import the sound as a "sound" and not as a "music" asset. 

 
 Preview the sound by clicking on the sound icon in the sounds tab.


Create a new rule by clicking on the 'new rule' button in the top right. 


Set the rule conditions to All and Actor receives event -> Overlaps or collides -> with Actor of type -> InvisiSpring


Drag and drop the new sound into the behaviour area for the new rule. 


Test out the new sound by pressing the preview button.