Replicating the Doppler effect with emitters
If you've ever stood by the side of a road as cars pass by, you've experienced the Doppler effect. Without getting into too much detail, the Doppler effect is the change in frequency of a wave (in this case, a sound wave) for an observer moving relative to its source. In the case of a car moving by a stationary observer (that is, you), the sound waves caused by the car's engine are being emitted closer together as the car approaches than they are as the car recedes. That's why a car emits a higher pitch noise the closer it gets and a lower pitch noise as it passes by and drives away. With the help of GameMaker's 3D audio functions, we can actually recreate this effect.
Getting ready
Once again, we'll be using the player object that we created in the Adding sound emitters and listeners recipe. Make sure that the Create event for obj_player
contains the following code:
audio_listener_orientation(0, 1, 0, 0, 0, 1);
Make sure that the Step event does...