Forum rules - please read before posting.

Audio Listener Following Switchable Players (and not rotating with them)

All right, so...
What I would like, for a more immersive game sound-wise, is to attach my audio listener to a player, therefore the sounds are more related with the proximity of my players with a hotspot, rather than camera based.
(I'm working on a 2.5D game, so the backdrops are 2D, camera is fixed or scrolling left-right / up-down; and I've two switchable players).
I'm having two issues:

1- I cannot attach an audio listener to both my players, 'cause the console gives me error "you are allowed to have only one listener" (or something like that). Even if, of course, my players aren't on scene at the same time, but only one at a time, swappable. If I attach the listener to one player only, when I swap player Unity tells me I don't have a listener in scene. If I attache the listeners to both players, Unity tells me I've two at the same time...!

2- The other issue is that I don't want my listener to rotate with my character. For instance: if my character is facing down, the audio-pan works perfectly (i.e. a car passing by from right to left, is creating a stereo panning right to left), but if my player is walking up, the listener is rotating with it and therefore messing my panning (i.e. if my player is facing up, I see the car passing from right to left, but I hear sound moving left to right).

I wonder...
Is it possible to have an empty object (let's call it "Listener") on scene with the audio listener attached to it, and a script telling that this Listener object is somehow attached to my generic Player, doesn't matter if it's PlayerA or PlayerB - whenever I swap, my listener is following the new player -, and without rotating with it? (i.e. following only XYZ position, not rotation)?

Might be a more Unity related question, but I wonder how to script the "following" of this object with the AC general player...



  • edited November 2019

    Yes, a single empty that follows the Player at all times would be the way to go.

    Inside a script attached to the listener:

    void Update ()
        if (AC.KickStarter.player)
                transform.position = AC.KickStarter.player.transform.position;
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.
Do NOT follow this link or you will be banned from the site!