So, I’m making a VR short film, so the camera is fixed on an axis and it only rotates. I have some objects with audiosources attached to each of them. How can I listen to each of them only when I’m looking at them?,If I have a 360 environment with camera fixed on an axis (like a VR short film)
Step 1 : Calculate a directional vector from your camera to the sound by doing :
Vector3 directionSound = positionSound - positionCamera //(normalize it or not, whatever you decide).
Step 2 : I suppose your camera “front” view is along Z axis. So you have it with
Camera.main.transform.forward
Step 3 : Just do the angle between the two direction :
float Angle = Quaternion.Angle(directionSound, Camera.main.transform.forward);
Step 4 : Just compare this angle with the minimum angle you need for playing the sound (Mostly the half of the FOV seems great, so about 60°)
Put a script that doing this on every audio source you need to play, and you’re done.