Collision Sound Framework


The Collision Sound Framework is a lightweight solution for subtle but effective Sound Effects for Collisions, in order to improve the realism and authenticity of the experience.

Sound Materials

To enable Collision Sound for a GameObject, add the MAGES Collision Sound Object component. This component requires a Rigidbody and Colliders to work (Does not require an Audio Source).

You can select the Collision Sound Material that determines how the object will sound from the Material drop down menu. You can also set the volume level of the specific object using the Local Volume slider.

Choosing Collision Sound Materials

Collision Sound Controller and Sound Playback

Collision Sound Controller in the Scene Hierarchy

The Collision Sound Controller also contains a database of all Collision Sound Material Audio Files. These sounds are loaded when the game starts.

Collision Sound Controller in the inspector

The Collision Sound Controller has a set of settings that can customize the system.

Sound Pool Size: The number of available Audio Playback prefabs allocated for playing back sounds. These can be reused, however it limits how many sounds can play at the same time. Lower values lead to less memory consumption.

Pitch Modulation Enabled, Pitch Modulation Range: Randomly set the pitch of every sound played within the range to make the sounds less repetitive.

Min Collision Volume: The minimum volume a sound can be played back at.

Max Collision Velocity: When a collision at or over this value happens, it is considered to be the highest impact possible, and the loudest sound is played.

Global Volume: Overall volume of all collisions.

Play Delay: Minimum time between collision sounds to avoid audio spam.

The Controller has a pool of Audio Playback prefabs that are used to play back all Collision Sounds. When a collision occurs, the Collision Sound Object requests an Audio Playback prefab from the Collision Sound Bank. The prefab is then loaded with the correct sound, its various parameters are set depending on the strength of the impact, and it is moved to the location of the impact. The sound is finally played back.

Audio Playback prefab at the location of an impact point

Audio File Structure

Each Sound Material’s Audio File contains a pool of different variations on the Sound Material, to make the sound more realistic. These pools also contain different sounds for different strengths of collisions.

Sound Material Structure

These different Sounds are all placed into 1 Audio file.

Sound Material Audio File Structure

When a collision happens, a pool is chosen at random. Then, depending on the strength of the collision, a Strength level is chosen.

For each Sound Material, the number of levels is the same across all of the pools. The duration of each level is also always the same. Every Sound Material can have a different number of levels, pools or different level duration.

Detecting Collisions

All collision detection provided by Unity’s collision system is used to detect initial collisions between Game Objects (usage of OnCollisionEnter). However, to further enhance the collision detection system, all new collisions that a GameObject might have while already colliding with another GameObject, are also now detected.

The rotation detection system uses the rotational difference of the object in between frames to recognize collisions. If the object is rotating and then suddenly stops, while already colliding with another object, it is assumed to have collided with something due to the sudden stop.

Change in rotation signifying a collision


Known Issues
1. When mimicking the movement of a collision in the air, while holding the Interactable and keeping it in collision with another GameObject, the rotation detection system will assume a collision has occurred and will play a sound.
2. Collision Sound is disabled when colliding with Deform Meshes.

Determining the Strength of a Collision

The Strength of a collision is defined as a value within (0,1] that defines how powerful a collision was. This requires setting a maximum strength for both Collisions detected by Unity, and with the rotation detection system.

  • For collisions using Unity’s OnCollisionEnter, the mass defined in the Rigidbody attached to the Interactable is used, multiplied by some constants.

  • For the rotation detection system, the size of the collider’s bounding box is used as a measure for setting a rotational difference threshold. For example, a pen can have many small rotations that would be ignored with a high rotational threshold, and a larger statue’s small collisions would be detected as big with a smaller rotational threshold.

Then, to pick a Strength in between the minimum and maximum values:

  • For collisions using Unity’s OnCollisionEnter, the impulse magnitude of the collision is used.

  • For collisions using the rotation detection system, the difference in rotation between the previous frame and the current frame is used.

The Strength is used to manipulate the Volume of the Audio Source, and is also used to pick a specific Strength Level from the Collision Sound Material.