Audibility2D • GitHub Wiki
Audibility2D is a Unity3D package designed to detect audibility levels of multiple audio sources in 2D space. Its primary purpose is to enable efficient enemy-hearing mechanics, with walls and other obstacles that dampen sound, creating more engaging gameplay.
- Burst
- Jobs
- Mathematics
- My Utilities package
To set up 2D mode:
- Create a basic Unity project with a standard
Tileset(2D Tilemap Editor package) - Add a secondary
Tilesetfor audio tiles (these can be created from the Asset menu).
Each Audio Tile can have an optional sound-dampening material attached, which defines how effectively sound propagates through it.
The system calculates dampening by subtracting the muffling strength of the current tile from the loudness of previously visited tiles, while also factoring in distance to the audio source. For visualization, you can use MufflingLevelAnalysisDrawer to display current tile muffling levels.
To define sound sources, attach the AudibleSound component to desired GameObjects. This component specifies the source’s loudness. Once added, you can preview audibility levels using the AudibilityUpdater. Beware that only Audibile Sounds that are located within tileset area will be considered for calculations.
You can also base on the OnDrawGizmos method in AudibilityUpdater to implement custom mechanics or visualization tools.
- Full-world computations are efficient, but rendering debug gizmos for all tiles can significantly impact performance. It is recommended to visualize only selected nodes.
- You can improve performance by processing only a limited section of the tileset around your entity. However, this requires using low-level API.
- The system is primarily tested on XY tilemaps; other layouts (e.g., XZ) may behave unpredictably.
Audibility2D is experimental for non-standard use cases. Use at your own risk.