Lesson 2

Table of Contents

Custom Volumetric Scripts

While the AkAmbient Simple, Large, and MultiPosition mode performs well for most ambience purposes, you should keep in mind that they are all based on sound points. This means that the sound positions will drive an Attenuation ShareSet and, for example, determine volume. This can be a challenge when mixing because you do not have a steady ambience volume in the entire area and will have to evaluate the mixing levels repeatedly in different locations. This is where you might want to customize your own script behavior and, as a solution to mixing ambiences in the Wwise Adventure Game, we have created an EventPositionConfiner script.

The EventPositionConfiner script is designed to look for a connected Trigger Collider and constantly move the sound position based on the AkListener's position. The result is that the sound's Attenuation ShareSet is set to a distance of 0 whenever the player is inside the Trigger Collider.

When the player exits the Trigger Collider, the Attenuation distance is based on distance from the listener game object to the nearest point on the Trigger Collider. As such, the spherical attenuation from the Sound Position will create an attenuation like the Trigger Collider mesh, with a slight round off in the edges.

[Tip]

The EventPositionConfiner script is updating sound position on an interval declared in the Inspector. Should you create a similar script, you'd want to keep a very high reposition speed (so it's fast enough to follow the speed of the Main Camera / AkListener) and add some spread on close distance in the Attenuation ShareSet (so if the sound position is not fast enough, it will be less noticable).

In the following steps, you will be adding the EventPositionConfiner to the River in the Village.

  1. In the Unity menu, go to Audiokinetic > Certification > 301 > Lesson 2, and select EventPositionConfiner.

  2. In the Hierarchy, go to the L2_4B - Village Environment Scene, expand Wwise, and select the River game object.

  3. In the Inspector, click Add Component, then search for 'EventPositionConfiner' and select it.

    In the Inspector, you'll see a Event Position Confiner component. In it, you have two properties: the Update Interval, which you should leave at 0.05, and the Event, which should be set to the Ambient_River Event.

  4. In the Event Name property, select the Ambient_River Event.

    You have now added the EventPositionConfiner script and assigned the River sound. To get a better understanding of how it works, let's play the game while monitoring the sound's position enclosed within the Collider Shape.

  5. In the Unity menu, go to Window > Layouts and select 2 by 3.

    This layout will place the Scene view next to the Game view, allowing you to play the game while monitoring the sound position, which is only visible in the Scene view.

  6. In the Hierarchy, go to the L2_4B - Village Environment Scene, expand Wwise, and select the River game object.

  7. Move your mouse into the Scene view, and press 'F' to focus on the River game object.

    You should now see the River in the Scene view. Surrounding the River you will see a green line, which is the Box Collider. Make sure you see the entire Trigger collider, by either scrolling out or moving the camera.

  8. Adjust your Scene view to viewing the entire Trigger collider.

    You're ready! All you need to do is play the game and test your work.

    [Tip]

    Make sure you have the 'Maximize On Play' disabled in the Game view. This option is disabled by default, but you might have chosen to enable it for convenience.

  9. Click Play to enter Play mode.

    [Note]

    The EventPositionConfiner script has been designed to show the sound's position as a small blue sphere. Like the camera icon and other gizmos, this sphere does not show up in the Game view or in the compiled version of the game.

  10. Rotate the Main Camera and look for a small blue sphere in the Scene view.

    Notice that when the Camera is outside the Trigger collider, the sphere will align to the nearest edge.

  11. Move the Main Camera inside the Trigger collider.

    Notice that the sphere is now located directly underneath the Main Camera (the camera is represented by a small camera icon).

  12. Press ESC to open the WAG menu and click Play again to exit Play mode.

As such, whenever the AkListener (added to the Main Camera) is inside the Trigger collider, the sound will remain completely centered. When it's outside the Trigger collider, the sound will be affected by its distance according to the Attenuation's Distance settings. Remember, the EventPositionConfiner script works with all Colliders (including Mesh, if set to Convex), which highly expands its applicability.


Was this page helpful?