I am working on a “2.5D” point n click adventure and before FMOD the unity listener was attached to the player character, so that the player could hear sounds that are near him. The listener rotation was LOCKED to camera rotation so that left/right works fine.
However, after adding FMODListener to the character prefab, FMOD’s StudioListener.cs seems to be setting the rotation of the listener, which is then being overridden by our custom script that locks rotation to camera.
This seems not-instant which is why a few bits out audio come out of the wrong speaker for just a few miliseconds.
I am wondering on how “to remove setRotation” from the FMOD Listener script, because rotation is being handled by our custom script.
I am no programmer, but looking at the code, I see:
private static void SetListenerLocation3D(int listenerIndex, Transform transform, Rigidbody rigidBody = null, GameObject attenuationObject = null)
Instance.studioSystem.setListenerAttributes(0, RuntimeUtils.To3DAttributes(transform, rigidBody), RuntimeUtils.ToFMODVector(attenuationObject.transform.position));
It uses full transform. I am wondering if I can somehow re-write this and remove rotation from transform…
You should be able to knock out the rotation by changing the call to
RuntimeUtils.To3DAttributes(transform, rigidBody) to something like
You can see To3DAttributes is pulling out the forward, up and position from the transform in RuntimeUtils.cs, so by passing in just the position you should get the overload that takes only a vector3 for the position and sets rotation to forward and up.
Cool! Yes I am totally looking for something like that, “just skip rotation mate”. Thank you!
Unfortunately, with these changes:
the FMOD listener still rotates with the game object. :-/
A quick video:
Note that in my snippet
RuntimeUtils.To3DAttributes(transform.position) both the
rigidBody was removed (this is responsible for velocity) and
transform was changed to
transform.position. The full transform has both position and orientation, by passing just the position you should avoid having the orientation applied.
thank you very much! I missed the “.position”.
It works smoothly now. Awesome! Thank you for your detailed responses!
So - just so I understand this. This means that the listener will absolutely ignore the object’s rotation & always face forward?
Also, I notice that “Min Extent” of the Spatialized stopped working, the sounds are now hard-panned L/R, instead of being a bit more enveloping.
Does this have to do with the changes I made? How is listener rotation linked to Min Extent of the Spatializer?
Or maybe this
RuntimeUtils.To3DAttributes function is also being used by many other objects and now that I’ve changed it, it also changed the behaviour of other sounds? Maybe I need to create a “custom” function, just for the listener? Hmm…
To be clear, passing transform.position into To3DAttributes will still give the listener a direction, it will face down the positive Z axis, with the positive Y axis pointing up. You can see this in the implementation of To3DAttributes, the version that takes only a position.
public static FMOD.ATTRIBUTES_3D To3DAttributes(this Vector3 pos)
FMOD.ATTRIBUTES_3D attributes = new FMOD.ATTRIBUTES_3D();
attributes.forward = ToFMODVector(Vector3.forward);
attributes.up = ToFMODVector(Vector3.up);
attributes.position = ToFMODVector(pos);
If you want to take direct control, just modify the StudioListener.cs, instead of calling RuntimeManager.SetListenerLocation, you can call the APIs it calls like studioSystem.setListenerAttributes. Otherwise attach the listener to a different game object that you have control over, ensuring the rotation matches what you want.