Doppler Effect mod
This is a pretty simple mod, all it does is add a function to play a sound, the sound played has a different gain depending on the distance between the sound origin and the player. The sound is lower for players who are further, and higher for players who are closer.Moving sound sources also have a pitch change while moving towards the player. If that moving sound emitter is above sound speed, the sound will be delayed. If at exact sound speed, you may see a sonic boom.
In real life, people are able to tell if a sound is getting closer or further, this is due to the Doppler Effect. The goal of this mod is to mimic this and to be used by developers.
Function syntax: sound_distance_play(pos, sound, sound_gain, distance, moving, yaw, vel, force_sound_speed)
"pos" is the sound origin position
"sound" is the sound file
"sound_gain" is the gain
"distance" is the max hear distance
"moving" is either true or false, true if the sound source is moving
"yaw" is used for moving sound sources, it can be something like "self.object:get_yaw()"
"vel" is used for moving sound sources, "self.object:get_velocity()" is recommended as a value
"force_sound_speed" is either true or false, if true, object velocity will be ignored and sound barrier breaking effects will be applied even to slow objects
Special thanks to TenPlus1, as the code to check the distance between the sound origin and the player was taken from mobs redo!
The code made by me is licensed under LGPL-2.1
The function which checks player distance (from mobs redo) is licensed under The MIT License
The sonic boom texture is licensed under CC-BY-SA-4.0
Only depends on default and tnt, both included in Minetest Game
For Minetest 5.1.1+
Download and browse code: https://github.com/CosmosScripter/sound_distance
Changelog:
Code: Select all
1-Added pitch changing (for now its just some kind of simple code for moving sound sources)
2-Added sound barrier breaking