Can 3D Sound Position Value 2.49b Receptor b Relative to Player not the Camera?

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. :slight_smile: 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?

[/wall of text]

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.

1 Like

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.

I simplified it so it only goes between 0 and 1 the closer the player gets to the source.

volume value = (max distance I want the sound to be heard from - own.getDistanceTo(player) / max distance I want the sound to be heard from

and then I modify the rollOffFactor so it can be heard up till that distance.

so ex:

maxDistance = 50
ears = own.getDistanceTo(player)
loudness = (maxDistance - ears) / maxDistance

sound.volume = loudness
sound.rollOffFactor = I put in 0.5 but I don’t really understand this

anyway thanks again so happy this was such a simple alteration.