0 votes

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?)

Godot version Stable
in Engine by (29 points)

1 Answer

0 votes

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!!

by (418 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.