So I wanted to do this for a long time and I saw that GDevelop added this feature a while ago but I’m not sure how it works and the wiki is a bit lacking at the moment in explanation and there was an example about it but again I’m not sure how to use that to reach what I want? so I’ll take it apart and help me understand what the events mean and how to use them, here we go…
First of all here is my goal with spatual sounds:
I want to create a feel of 3d sound in a scene, for example (the player is on the far left and there is a engine at the far right, the player starts to walk towards the engine and the sound volume starts to increase gradually and then the player goes back again and the sound volume starts to decrease and so on, very simple stuff it should be, nothing too complicated)
I want the sound to be perfectly smooth and increase and decrease by 1 or even lower, I want it to be super smooth.
Based on the fact that GDevelop uses HowlerJS for spatial sound. If you look at the documentation of this library, I can assume that this means:
Sets the spatial position of the listener/player
Sets the direction the audio source is pointing in the 3D cartesian coordinate space. Depending on how directional the sound is, based on the cone attributes, a sound pointing away from the listener can be quiet or silent.
Set position of sound
Sets the 3D spatial position of the audio source for this sound or group relative to the global listener.
@E1e5en Thanks for replying, I’ve seen the example and read this but I still don’t get how it works to be honest, I’m a bit confused about it…
The one in the example is set to something like Player.X() / 100 and Player.Y() / 100 because it’s 800*800 but what if the scene is bigger? what exactly should I change? and do I have to do that with every single sound I add in the scene?
Also the one in the example is not smooth enough, it goes from 0 then 25 then 50 and so on…
But I want it to be very smooth like from 1 then 2 then 3 and so on based on the player position in the scene…
Like for example
A player here >>>> an engine is here
And the player moves closer to it and sound increase very smoothly from 1 to 100 or even from 0.1 to 100 based on the player position of course…
I’ve been trying since yesterday but I’m just confused about the whole thing…
@arthuro555 Do you have an idea about this or how to make this possible? also do you think there is a better easier way than using spatial sound to get the increase and decrease in sound smoother?
Now I hope someone has a cleaner idea than this to be honest, but if not then that’s alright I guess…
But what you see in the picture above is kind of what I’m aiming for…
Smooth sound increase and decrease based on player distance.
If someone have a cleaner idea, let me know about it…
If you write yourself, then in your case, the volume level depends on the distance. We form the ratio (assume that the sound is not audible at a distance of 600 px to the player):
600 (px) = 100
X (px) = Y
As a result, we get if the player is 200 px away (X = 200):
Y = 200 * 100 / 600 = 33.33
Since we move away from the sound source, we get:
100 - 33.33 = 66.67
As a result, at a distance of 200 px from the sound source, the volume level should be equal to 66.67.
You find the percentage of the distance from the maximum distance, and subtracting it gets the value.
@E1e5en Thanks a ton!
Test 2 was exactly what I was aiming for, but I have a question about it:
Now I made a second “SourceSound” instance and gave each one a text variable called “One” for the first one and “Two” for the second and then I ran each sound on a different channel and now I have 2 sounds in the scene that uses spatial sounds at the same time which is perfect for what I need but I was wondering, is this the right way to do it in case I need to use several sounds in the same scenes? or is there another better way? because if this is how it is then I’ll be making a new event for every single new sound I want to add in the scene and I’m totally okay with that but I thought to ask you maybe there is a better way to it if I want more than one sound in the scene.
This question is totally for optimization purposes you know…
I’ll be waiting for your input on this and I want to thank you so much for the example as it totally clears everything and I now understand how spatial sound actually work in the engine, the example in the engine was just complicated for me to understand as I never used spatial sounds before.
Unfortunately, I cannot tell you exactly. But if you need to use several sounds in a scene, how is it different? You can turn off sounds depending on the distance. I suppose if during the development you have problems with optimization, then you can return to this question.
It might also be worth considering obstacles between the audio source and the player (use raycast to check). For example, if there is a wall between them, then muffle it (or turn it off) by a certain factor. Well, these are already ideas for implementation.
I was actually going to ask about this, I’m glad you mentioned this.
You said “muffle it” >>> is this possible inside the engine?
Another example would be outdoors rain and indoor rain sound.
Going from out to in … you hear this muffle or pressure on the sound, do I have to use separate sound for each effect? and then call it when I want then decrease the other sound and slowly increase the sound I want?
I’m outdoors so the rain sound is at maximum
I then go indoors (there is this small transition which is going from out to in)
Then I’m in so the rain sound in muffled and so I decrease the outdoors rain sound and increase the indoors rain sound.
Do I have to create 3 versions of the same sound? or there is actually a way to muffle/edit sound inside GDevelop directly?
@E1e5en yeah got you, I think it is possible but it’s going to be a bit annoying to do but I’m sure it’s possible to create that effect using different edited versions of the sound.
It’ll be a while though before I get into this kind of details so I’m just going to keep this for now on my note and when the time comes I’ll see how I can do this effect.