AudioStreamPlayer2D changing volume based off distance to (0,0), not to screen center

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By indigo

I have an AudioStreamPlayer2D on a moving node and my player character with a Camera2D attached.

For some reason, the AudioStreamPlayer’s volume seems to be based off how close the node is to the global origin, not to the screen center as determined by the Camera2D.

Is there some sort of camera setting that needs to be changed to make this work correctly (e.g., have it be louder when the sound is closer to the player?)

:bust_in_silhouette: Reply From: Pomelo

If you read the AudioStreamPlayer2D doc, it says it functions with the distance to the center of the screen. So I too would expect it to work as you intended, but if you read the Camera2D doc, you will see that its position (which is the one changing when following the player), does not represent the actual position of the screen.

I find quite odd that how this works, but I dont have a firm grasp of what goes behind a game engine, so who knows. I dont think I have a good solution for your problem, but you now at least know why it isnt working (the center of the screen does remain at (0,0), even when your camera moves)

You could try getting using get_camera_screen_center() and then changing the screen center??? (dont know how haha)

maybe try with Viewport.canvas_transform = get_camera_screen_center()

Hope it helps!!