GameMaker: Studio

GameMaker: Studio

View Stats:
3D / Directional sound? A question about "play_sound_at" and "listeners"
I was thinking of setting up a fairly basic directional sound system in my current hobby project. But its not working the way I was expecting and experimenting and reading up on it hasn't gotten me anywhere.

Here is the code in question....

audio_listener_position(room_width / 2, room_height / 2, 0) audio_play_sound_at(sound,x,y,0,0,0,0,false,100)

For reference the position of the object emitting the sounds X / Y coordinates are 830 / 600.

And the room size is 1920x1080 so the listener should be at X / Y coordinates of 960 / 540.


Based on the code I'm expecting the sound to be only slightly "offset" with what speakers it comes out of since the position of the object making the sound and the listening position are very close together.

Oddly though, what is occuring is the sound is coming heavily out of the right speaker only with nothing coming out of the left speaking.


What am I doing wrong or missing here?
< >
Showing 1-5 of 5 comments
Sistermatic™ Jan 8, 2016 @ 12:23pm 
I spent 4 hours on similar issue yesterday and found the "help" all over the place with no definitive answer. It came down to the orientation to the player in relation to the sound, I worked that out by myself but none of the "fixes" solved my issues.

In my case I had moving targets and moving player but here are the code snippets for a static sound (water tank for mine). This seems to work fine.

in player STEP (this solves the orientation fine)
// update the listender if we move if (we_moved) { xt = x + cos(degtorad(direction)); yt = y - sin(degtorad(direction)); audio_listener_position(x, y, 0) audio_listener_orientation(xt, yt, 0, 0, 0, 1) }

In my static target CREATE
s_water=audio_emitter_create(); audio_emitter_falloff(s_water, 25, 50, 1); audio_emitter_position(s_water,x,y,1); audio_play_sound_on(s_water,snd_water,true,10);

Note the sound is looped and drops off using falloff. If you want it to turn on/off you'll need to shift the play_sound_on to a step event and test if it's running.

Hope this helps.
🐭 Jan 8, 2016 @ 12:28pm 
Originally posted by Sista:
I spent 4 hours on similar issue yesterday and found the "help" all over the place with no definitive answer. It came down to the orientation to the player in relation to the sound, I worked that out by myself but none of the "fixes" solved my issues.

In my case I had moving targets and moving player but here are the code snippets for a static sound (water tank for mine). This seems to work fine.

in player STEP (this solves the orientation fine)
// update the listender if we move if (we_moved) { xt = x + cos(degtorad(direction)); yt = y - sin(degtorad(direction)); audio_listener_position(x, y, 0) audio_listener_orientation(xt, yt, 0, 0, 0, 1) }

In my static target CREATE
s_water=audio_emitter_create(); audio_emitter_falloff(s_water, 25, 50, 1); audio_emitter_position(s_water,x,y,1); audio_play_sound_on(s_water,snd_water,true,10);

Note the sound is looped and drops off using falloff. If you want it to turn on/off you'll need to shift the play_sound_on to a step event and test if it's running.

Hope this helps.
Neat, I never have used this, but its cool that someone has figured this out, I think I'm going to play around with it.
Sistermatic™ Jan 8, 2016 @ 12:50pm 
Originally posted by YeeFee:
Neat, I never have used this, but its cool that someone has figured this out, I think I'm going to play around with it.
A word of caution, when I put up code snippets it's not neccessarily "right" but if it works - for me - I'm happy to share. :)

tbh. I'm not happy with how this is implemented but that could be my newness to GMS.
🐭 Jan 8, 2016 @ 1:34pm 
Originally posted by Sista:
Originally posted by YeeFee:
Neat, I never have used this, but its cool that someone has figured this out, I think I'm going to play around with it.
A word of caution, when I put up code snippets it's not neccessarily "right" but if it works - for me - I'm happy to share. :)

tbh. I'm not happy with how this is implemented but that could be my newness to GMS.
Nah I know its not the best, but it works and Im sure I can figure out an even better way of doing it.

But for someone new to GMS, the fact that you're trying stuff out is great.
Originally posted by Sista:
I spent 4 hours on similar issue yesterday and found the "help" all over the place with no definitive answer. It came down to the orientation to the player in relation to the sound, I worked that out by myself but none of the "fixes" solved my issues.

In my case I had moving targets and moving player but here are the code snippets for a static sound (water tank for mine). This seems to work fine.

in player STEP (this solves the orientation fine)
// update the listender if we move if (we_moved) { xt = x + cos(degtorad(direction)); yt = y - sin(degtorad(direction)); audio_listener_position(x, y, 0) audio_listener_orientation(xt, yt, 0, 0, 0, 1) }

In my static target CREATE
s_water=audio_emitter_create(); audio_emitter_falloff(s_water, 25, 50, 1); audio_emitter_position(s_water,x,y,1); audio_play_sound_on(s_water,snd_water,true,10);

Note the sound is looped and drops off using falloff. If you want it to turn on/off you'll need to shift the play_sound_on to a step event and test if it's running.

Hope this helps.

Thanks for the response!

I hadn't considered the orientation as being a potential issue. I had only used the command to set the position itself. I figured leaving the orientation alone would cut it out of the equation and make my where the sound is coming from entirely determined by the distance from the listener without having to deal with facing as well.

Since the listener in my case wasn't an actual object but literally just the center of the screen I guess I'd have to try to back the orientation pointing "into" the screen.



I also see you're using audo emitters. In my testing I was just using the "play_sound_at" command and not actually creating emitters. I figured I could get away without using emitters since I wasn't planning on doing anything fancy. Guess I'll brush up on them again.



Originally posted by YeeFee:
Is that hamster Ebichu?
< >
Showing 1-5 of 5 comments
Per page: 1530 50

Date Posted: Jan 8, 2016 @ 12:09pm
Posts: 5