Search Unity

Audio 2D Audio rolloff/max distance not working (spatial blend is set to 3D)

Discussion in 'Audio & Video' started by viveleroi, Jun 26, 2017.

  1. viveleroi

    viveleroi

    Joined:
    Jan 2, 2017
    Posts:
    91
    I've added a looping audio source to a gameobject in my world. I'm trying to get the volume to increase when you get closer, while no longer being audible more than eight tiles away.

    When I try using the logarithmic rolloff, with any min/max distance, the volume never seems to increase/decrease and it never seems to disappear completely. It's always a bit quieter than the track by default is, but I can at least hear it.

    When I try using the linear rolloff, I can't hear the audio at all, even when I'm standing right next to the gameobject.

    As other threads mention, I have spatial blend set to 3D. I'm tried toying with the min/max distances, doppler values, etc, but according to help threads I've done everything I should have.

    I'm wondering if it's something wrong with the camera positioning? I use this script to follow the player:

    Code (csharp):
    1.  
    2. public class FollowPlayer : MonoBehaviour {
    3.     public GameObject player;
    4.     private Vector3 offset;
    5.  
    6.     void Start() {
    7.         offset = transform.position - player.transform.position;
    8.     }
    9.        
    10.     void LateUpdate() {
    11.         transform.position = player.transform.position + offset;
    12.     }
    13. }
    14.  
    The initial offset is Vector3(0, 0, -10). I'm not sure what the -10 is for, it's 2D game, but maybe that's affecting this audio?


    EDIT: I solved this by moving the Audio Listener to my player. Somehow, even though the camera followed my player, the positions weren't right.
     
    Last edited: Jun 26, 2017