ADXTutorials

ADX & Unity Synchronization [Part 2]

In the first part of this tutorial, we saw a simple way to synchronize the display of the subtitles with the playback of audio dialog. In this post, we will introduce synchronization based on Cue markers, allowing us to shake the camera and door in Unity in response to audio events.

Setting up the Cue

First, we prepare a Cue in AtomCraft with several Waveform Regions on the timeline, each one corresponding to a knock on the door. Then, we add a Marker at the beginning of each sound, as shown in the diagram below.

Scripting

In Unity, the OnCallback function provided by the CriAtomExSequencer class will allow us to be notified when the position of a Marker is reached during the playback of our Cue. In the script below, we retrieve the CriAtomSource attached to the object, play it every 5 seconds, and then output some info with Debug.Log when a Marker is reached.

*Note that the SetEventCallback() function used with previous versions of the CRIWARE plug-in is now deprecated.

Animation

In our sample scene, as shown below, we associate a vibrating animation with the door, which is played each time it receives a trigger called “Impact”.

On the script side, we simply need to call animator.SetTrigger(“Impact”); in the body of the callback function to make the door shake when a Marker is reached during the playback of the ADX Cue.

For the camera, we used the following script that relies on Perlin noise to achieve a more natural shaking movement. https://github.com/keijiro/Reaktion/blob/master/Assets/Reaktion/Utility/JitterMotion.cs

We modified the code to cause temporary random shakes rather than a sustained jitter.
Of course, for a more dramatic effect, you could also use Unity particles and prefabs to make small debris fall from the walls and ceiling.

By itself, ADX is capable of some impressive work, such as playing back a large number of voices with a very low CPU load. However, the sense of immersion and realism in your game can be greatly improved when the audio and other systems, such as animation and VFX, are synchronized. We hope this 2-part tutorial gave you some ideas for your own games!