I have static cameras so I would like the sound to get louder the closer the player character gets to the sound source. Not the closer the camera gets. Because I want a static scene. How do I change this?
The position variable seems to change absolutely nothing. The sound always becomes louder relative to proximity to the active camera and nothing else. What does the position variable even do? There is no change whatsoever whatever coordinates I input.
Details: The wav files are mono and the 3D feature with roll off does function perfectly. It is simply stuck at being relative to the proximity of whatever active camera. So I cannot use the sound to really guide a player with a static cam to the back of a scene since the sound will only ever seem to come out of the static camera in front of the scene. So the 3D sound only seems to make sense for 1st Person View.
Maybe I should just write my own script that has the sound increase with player proximity using the same mono file twice for each ear?
It’s distance to player over distance to camera, more or less.
from bge.logic import getCurrentController, getCurrentScene
own = getCurrentController().owner
scene = getCurrentScene()
player = scene.objects["Player"]
reference_distance = own.getDistanceTo(scene.active_camera);
toPlayer = own.getDistanceTo(player)/reference_distance
min_volume = 1.0; max_volume = 2.5;
sound = own.actuators["Sound"]
sound.rollOffFactor = toPlayer
sound.volume = max(min_volume, (1-toPlayer)*max_volume)
Note that this means extra logic per sound so you might want to look into doing some culling.
Also min and max volume could be set through properties or what have you.
It works, thank you. I had to modify it only a little, but this is a great solution. I had to fix the rollOffFactor with a set value and toPlayer controls the volume. So the Player getting near the sound makes the sound louder. I’ll post something else tomorrow.