Legacy GM Help with 3D sounds?

Hi, I want to make it so that sounds like car engines and gun shots in my top down game can only be heard from a certain distance away, and have them fade out as the object making the sound gets farther away. I've been watching videos and reading things, but I don't get it. Maybe they're not very good tutorials, or maybe I'm just slow. Either way I can't find a clear and simple way for my little brain to understand how to do it.

I don't want to sound like someone who can't be bothered to learn on their own but I literally can't do this ****.
 
https://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/audio/audio_play_sound_at.html

audio_play_sound_at is what you're looking for.

It lets you pick where in the room to play the sound and how far away the sound reaches. If the player is outside of this range, they won't hear the sound, and it will get louder as they get closer to the source.

Ex:
Code:
audio_play_sound_at(snd_Waterfall, x, y, 0, 100, 300, 1, true, 1);
The sound, waterfall, will play at the x and y position of the calling instance and 0 on the z axis. If I'm not mistaken, the 100 is the distance away from the source that the sound should start to fade, and 300 is how far away until the sound has completely faded. 1 is the falloff factor, which should be changed based on what sound model you set with audio_falloff_set_model, but the default of 1 is usually fine. https://docs2.yoyogames.com/source/..._reference/audio/audio_falloff_set_model.html

True makes sure the sound loops, and 1 is the priority.
 
https://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/audio/audio_play_sound_at.html

audio_play_sound_at is what you're looking for.

It lets you pick where in the room to play the sound and how far away the sound reaches. If the player is outside of this range, they won't hear the sound, and it will get louder as they get closer to the source.

Ex:
Code:
audio_play_sound_at(snd_Waterfall, x, y, 0, 100, 300, 1, true, 1);
The sound, waterfall, will play at the x and y position of the calling instance and 0 on the z axis. If I'm not mistaken, the 100 is the distance away from the source that the sound should start to fade, and 300 is how far away until the sound has completely faded. 1 is the falloff factor, which should be changed based on what sound model you set with audio_falloff_set_model, but the default of 1 is usually fine. https://docs2.yoyogames.com/source/..._reference/audio/audio_falloff_set_model.html

True makes sure the sound loops, and 1 is the priority.
That's it?????????? I don't need to do the emitter and listener crap?
 

Dr_Nomz

Member
Funny, I was just about to ask about this lol.

OblivionSkull, is 1 just for linear sound, like the chart on that link you posted?
 
Funny, I was just about to ask about this lol.

OblivionSkull, is 1 just for linear sound, like the chart on that link you posted?
I think so, I'm not entirely sure as I've never changed the falloff factor from its default.

"falloff factor - The falloff factor is used in distance attenuation based on the inverse distance model and sets the final minimum threshold for a sound with falloff."

I'm assuming if you have falloff factor of 2, then the the falloff will be twice the normal size, but I could be wrong.
 
Listeners/emitters are for more complex sound. I think that if you just want a sound to play at a spot and fade as it gets farther from the player, then audio_play_sound_at is all you need.
It's not working. I want it for the sirens on the police cars but no sound is playing.
Code:
if(distance_to_object(obj_player) < 300){
        mySiren = audio_play_sound_at( snd_siren1 , x , y , 0 , 100 , 300 , 1 , true , 1 );
    }
I don't know what I did, the code seems simple. I read the article you linked, and put this code in a step event in the player object:
Code:
audio_listener_position( x , y , 0 );
audio_listener_orientation(0, 0, 1000, 0, -1, 0);
 
It's not working. I want it for the sirens on the police cars but no sound is playing.
Code:
if(distance_to_object(obj_player) < 300){
        mySiren = audio_play_sound_at( snd_siren1 , x , y , 0 , 100 , 300 , 1 , true , 1 );
    }
I don't know what I did, the code seems simple. I read the article you linked, and put this code in a step event in the player object:
Code:
audio_listener_position( x , y , 0 );
audio_listener_orientation(0, 0, 1000, 0, -1, 0);
First, you don't need the distance to object part. The sound is going to be playing at the coordinates of the car whether the player is within range or not. It will always be playing. However, you won't be able to hear it unless you are within 300.

The audio_listener_position is correct.

I'm not super familiar with audio listeners myself, I think I had to post a thread about it a while back. In my game, I have

Code:
audio_listener_orientation(0,-1,0,0,0,-1);
That seems to work for me.
 
First, you don't need the distance to object part. The sound is going to be playing at the coordinates of the car whether the player is within range or not. It will always be playing. However, you won't be able to hear it unless you are within 300.

The audio_listener_position is correct.

I'm not super familiar with audio listeners myself, I think I had to post a thread about it a while back. In my game, I have

Code:
audio_listener_orientation(0,-1,0,0,0,-1);
That seems to work for me.
Now, the sound isn't following the cop cars, and I can still hear the sound even when they are over 300 pixels away.
 
Last edited:
Now, the sound isn't following the cop cars, and I can still hear the sound even when they are over 300 pixels away.
Try something like this.

In the car's create event:
Code:
audio_falloff_set_model(audio_falloff_linear_distance); //standard linear model
In the car's step event:
Code:
with(obj_player){
audio_listener_position(x, y, 0); //position listener at player's coordinates
audio_listener_orientation(0,-1,0,0,0,-1);
}

audio_play_sound_at(snd_siren1, x, y, 0, 100, 300, 1, true, 1); //play the sound at the car's coordinates
If that doesn't work, check to see if you've set the actual sound's output to 3D. I read some where that you should do this, but I haven't done this with my game and my sounds work just fine, so idk.

Also, if you're only wanting one sound to play for the group of cars instead of six sounds for six cars, then you should check to make sure the sound isn't already playing.
Code:
if !audio_is_playing(snd_siren1){
audio_play_sound_at(snd_siren1, x, y, 0, 100, 300, 1, true, 1); //play the sound at the car's coordinates
}
If all else fails, try this tutorial. Though, it does use emitters, which I'm not familiar with. Regardless, the code I provided works in my game so there shouldn't be any reason for it not to in yours.
 
Try something like this.

In the car's create event:
Code:
audio_falloff_set_model(audio_falloff_linear_distance); //standard linear model
In the car's step event:
Code:
with(obj_player){
audio_listener_position(x, y, 0); //position listener at player's coordinates
audio_listener_orientation(0,-1,0,0,0,-1);
}

audio_play_sound_at(snd_siren1, x, y, 0, 100, 300, 1, true, 1); //play the sound at the car's coordinates
If that doesn't work, check to see if you've set the actual sound's output to 3D. I read some where that you should do this, but I haven't done this with my game and my sounds work just fine, so idk.

Also, if you're only wanting one sound to play for the group of cars instead of six sounds for six cars, then you should check to make sure the sound isn't already playing.
Code:
if !audio_is_playing(snd_siren1){
audio_play_sound_at(snd_siren1, x, y, 0, 100, 300, 1, true, 1); //play the sound at the car's coordinates
}
If all else fails, try this tutorial. Though, it does use emitters, which I'm not familiar with. Regardless, the code I provided works in my game so there shouldn't be any reason for it not to in yours.
I just learned how to use emitters it wasn't as hard as I first thought.
 
Top