audio_listener_set_velocity

Changes the velocity of the given listener within the audio space.

Syntax:

audio_listener_set_velocity(index, x, y, z);


Argument Description
index The listener to get the data for (default 0).
x The x velocity of the listener (default 0).
y The y velocity of the listener (default 0).
z The z velocity of the listener (default 0).


Returns: N/A


Description

This function can be used to give the given listener doppler effects and simulate audio motion based on the vector that is resolved from the given relative x, y and z positions (for more information on vectors, please see Maths - Vectors). The default listener index is 0, but you can use the function audio_get_listener_info to get the different indices available for the target platform.

If the given listener is not ever going to move, or the movement is not a constant motion, you would normally not need to set these values, but, for example, if you are making a scrolling game where the player has a constant bottom to top movement and the enemies a constant top to bottom movement, you would set the listener and emitter velocities (for emitters you would use audio_emitter_velocity) to the appropriate vectors to simulate the correct doppler effect as they move past the player instance.

The image below shows how this could be setup for the example game given above:


Example:

var num = audio_get_listener_count();
for(var i = 0; i < num; ++i;)
   {
   var info = audio_get_listener_info(i);
   var data = audio_listener_get_data(info[? "index"]);
   if data[? "vx"] != 0
      {
      audio_listener_set_velocity(info[? "index"], 0, 0, 0);
      }
   ds_map_destroy(info);
   ds_map_destroy(data);
   }

The above code checks the number of listeners available then loops through them and if their x velocity is not 0, it sets their velocity values to 0, 0, 0.


Back: Audio Listeners
Next: audio_listener_set_orientation
© Copyright YoYo Games Ltd. 2015 All Rights Reserved