- Home /
Simulate 3-D sound without Audiosource
Hey there,
I am trying to get a 3-D sound effect but unfortunately I cannot rely on the built-in solution because I am using G-Audio which does not work with Unity's Audiosources.
So I have several objects that are positioned in a virtual room. Every object sends Audio to its own track with separate panning and volume. Now I want to adjust the panning and volume of these tracks based on the position and rotation of the camera relative to these objects. Like simulated 3-D audio…
Adjusting the gain based on position is no problem so far. However, I am struggling with the panning.
Here is a script that is attached to my camera object. The target object is supposed to be the object emitting sound.
public float GetAngle(Transform target) {
Vector3 _vecRotation = target.position - transform.forward;
float _angRotation = Mathf.Asin (Vector3.Cross (_vecRotation.normalized, Vector3.up).z);
Vector3 _vecPosition = target.position - transform.position;
float _angPosition = Mathf.Asin (Vector3.Cross (_vecPosition.normalized, Vector3.up).z);
float _sumAng = _angRotation + _angPosition;
if (_sumAng > 1f)
_sumAng = 1f;
if(_sumAng < -1f)
_sumAng = -1f;
return _sumAng;
}
I think I am following a wrong approach.. I thought I have to calculate the rotational and positional panning separately but this might be completely wrong. Could someone with better knowledge of vector maths please help me? All I want is panning based on the position and rotation of the camera relative to the object. -1 for Left and +1 for Right.
Your answer
![](https://koobas.hobune.stream/wayback/20220613182638im_/https://answers.unity.com/themes/thub/images/avi.jpg)