M
MHBlacky
Guest
Hey guys,
I am currently working on a first person shooter and until now I always only used audio_play_sound for all sounds.
Today I wanted to start setting up proper 3D sounds for the enemies' guns. So that I get a falloff depending on the distance to the enemy and also a pan change depending on where I look.
What I did: I the player's step event I update the listener's position:
lookat_x/y/z should definitely work because the code is the same that I also use as my camera's look-at-point.
As up_x/y/z I just used the z-axis because the player's 3D body orientation never changes so the up direction is my game is always along the z-axis.
Then in my enemy object I use the following code when shooting:
The sound falloff works perfectly fine but the problem is that the pan seems to ignore the 3rd dimension completely.
When the player's x-value is smaller than the enemy's the sound is played more on the right speaker and the other way round when the player's x value is larger. The listener's orientation seems to be ignored completely...
Have tried the same thing with an emitter --> same problem.
Am I missing something obvious here? Does anyone maybe have an idea how i can get the pan to work properly?
I am currently working on a first person shooter and until now I always only used audio_play_sound for all sounds.
Today I wanted to start setting up proper 3D sounds for the enemies' guns. So that I get a falloff depending on the distance to the enemy and also a pan change depending on where I look.
What I did: I the player's step event I update the listener's position:
Code:
// Position
audio_listener_position(x, y, z);
// Orientation
var r = 1; // radius (doesn't matter here because it's only about the orientation not the vector length)
var lookat_x = x + r * sin( degtorad(90+obj_player.pitch) ) * cos( degtorad(-obj_player.viewdirection) );
var lookat_y = y + r * sin( degtorad(90+obj_player.pitch) ) * sin( degtorad(-obj_player.viewdirection) );
var lookat_z = z + r * cos( degtorad(90+obj_player.pitch) );
var up_x = 0;
var up_y = 0;
var up_z = 1;
audio_listener_orientation(lookat_x, lookat_y, lookat_z, up_x, up_y, up_z);
As up_x/y/z I just used the z-axis because the player's 3D body orientation never changes so the up direction is my game is always along the z-axis.
Then in my enemy object I use the following code when shooting:
Code:
audio_play_sound_at(snd_rifle, x, y, z, 100, 50, 1, false, 1);
When the player's x-value is smaller than the enemy's the sound is played more on the right speaker and the other way round when the player's x value is larger. The listener's orientation seems to be ignored completely...
Have tried the same thing with an emitter --> same problem.
Am I missing something obvious here? Does anyone maybe have an idea how i can get the pan to work properly?