Hello! I’ve been having trouble getting the spatial positioning of 3D sound events to work correctly in my c++ game engine. I believe I’m simply misunderstanding something and it is likely a simple fix.
My game is a 2D platformer with positive X axis being right and positive Y axis being down. I’ve been trying to set things up properly so that the sounds are positioned correctly in FMOD. I originally tried forward vector being {1, 0, 0} and up vector being {0, -1, 0} but that resulted in all sounds events to only be on the x axis and y and z are always 0. This is going off of what we see in the FMOD Studio profiler. I’m happy to go into more detail but honestly am not sure what else to provide. Thanks!
Hi,
I would expect a positive forward vector and a negative up vector to work, which makes me suspect that the 3D attributes of the events are being set incorrectly. Could I get you to provide a code snippet of how you are passing your engine’s coordinates to FMOD with Studio::EventInstance::set3DAttributes, and any other transformations you are making to the coordinates for this purpose?
You may also wish to check yourself what the coordinates are in your engine and compare them to the coordinates retrieved using Studio::EventInstance::get3DAttributes to check for any discrepancies.
Hey Louis, thanks for the response. Here’s what the code looks like for when I setup my listener attributes.
s_fmod3DAttributes.forward = FMOD_VECTOR {1.0f, 0.0f, 0.0f};
s_fmod3DAttributes.up = FMOD_VECTOR {0.0f, -1.0f, 0.0f};
s_fmod3DAttributes.position.x = position.x;
s_fmod3DAttributes.position.y = position.y;
s_system->setListenerAttributes(0, &s_fmod3DAttributes);
and here is where I set my event instance
FMOD_3D_ATTRIBUTES attributes {};
attributes.position.x = position.x;
attributes.position.y = position.y;
attributes.position.z = 0;
attributes.forward = FMOD_VECTOR {1.0f, 0.0f, 0.0f};
attributes.up = FMOD_VECTOR {0.0f, -1.0f, 0.0f};
eventInstance->set3DAttributes(&attributes);
I checked EventInstance::get3DAttributes and it is returning what I’m putting in. Does any of the above code look wrong? Thanks!
The issue here appears to be that the forward vector is being set incorrectly to the X direction. Even though your up vector is flipped, the forward vector should still be in the Z direction. Given my unfamiliarity with your engine, I’m not sure whether a positive or negative Z direction forward vector is appropriate, but try both and see which one works.
Thank you Louis! This was indeed the issue. Here is what I ended up with given my coordinate system.
attributes.forward = FMOD_VECTOR {0.0f, 0.0f, -1.0f};
attributes.up = FMOD_VECTOR {0.0f, -1.0f, 0.0f};
1 Like
attributes.forward = FMOD_VECTOR {0.0f, 0.0f, -1.0f};
attributes.up = FMOD_VECTOR {0.0f, -1.0f, 0.0f};
So this is for the event instance 3d attributes, is your listeners forward and up vectors the same too? I’m having the same problem
Just to clarify, what positive/negative direction is your coordinate system using for each axis? Are you using the same setup as @jmcmorris?
The same yeah. Really the issue was because I was not passing null for attenuation position: Top down 2D spatial sounds - #4 by tlconflict
1 Like