Friday 7 August 2015

Interactivity Through Sound

For those interested in other devs writing on sound design you can read the fantastic set of articles by the developer of Cogmind here: Sound in Roguelikes, Sound Design, Ambient Sound

This week saw the introduction of sound into Chronicles of Aether.

Sound is immensly important in games as it provides one of the two main ways the computer can interact with our senses (the other being sight). With such a large portion of the players experience of a game relying on this it is a shame it tends to get neglected by developers so often.

In Chronicles of Aether sound is seperated into 3 main categories.
  1. Music. Each level has a background song that plays, picked to evoke an emotion that reflects the design of the level. For example a foreboding eerie track for a crypt, or a happy jaunty tune for a bright forest.
  2. Ambient sounds. Sounds that play due to some logic (such as repeat infinitely, or once every 10-20 seconds etc). These are used to give a further depth to the atmosphere building for the level. Examples are groans and echoing splashes for a dungeon, Birds and insects for a forest.
  3. Effect Sounds. These are sounds that play in reaction to some action an entity in the world has made. An example being the sound of a sword strike or a fireball explosion.
After implementing these sounds I had entities exclaiming when they saw an enemy, groaning when they were wounded, and a cacophany of other sounds as they bashed each other to death. Sitting back I looked at this scene a realised it felt contrived, all this noise that meant nothing to anyone but the player.
Then I had an idea. Why don't I add meaning to the sounds, something that the entities can act on? With this in mind I added a piece of data to each of the dynamic sounds. Entities close enough to hear the sound would have that data inserted into their ai, to process as they will. Suddenly the world came alive. Sounds of fighting would draw in nearby entities to investigate, enemies would shout out the location of the player, informing their allies of the players position and calling them forward. Wounded creatures could inform their healer allies that they needed assistance. And every piece of this interaction was perceivable to the player, as they could hear the creatures talk to one another.

Now I'll get quickly into how this is implemented:

  • Background and ambient sounds have no in game meaning other than to create atmosphere, and therefore the code playing them is very simple.
  • Sound effects have a few different configuration settings:
  • Max Volume. This is the maximum (before attenuation) volume.
  • Max Range. This is the range where attenuation will have brought the volume to zero.
  • Attentuation Offset. The range value to start attenuating from. Anything below this plays at max volume.
  • Data. The data to impart to the entities who hear it.  

Whenever a sound is played it gets all the entities within a sphere around the source defined by the maximum range. Then for each entity it tries to path towards it using AStar. If it can find a path with less steps than the maximum range that entity 'hears' the sound and gets the data.
It does the same for the player, to calculate the volume for the sound to be played at.

No comments:

Post a Comment