Audio clip doesn't sound the same despite its position

I’m currently implementing the coin sound for the pickup in the TileVania project. Rick explains to set the parameter for position to the camera so that the sound will play the same no matter yet. But…when I test the game sometimes it will play out of one ear or the other with my headset like if it’s coming from a specific direction. Is this as intended?

Hi,

This sounds as if the sound was not being played at the camera position. Maybe the cinemachine caused this problem. Were you able to recognise a pattern, e.g. did the sound seem to come from the left when you moved to the right?

Yes! That’s exactly what is happening. And vice versa when I’m coming from the left. I thought maybe it was Cinemachine.

Could you try to change the Update method of the cinemachine in the cinemachine brain component?

So if I change it from Smart Update to Late or Fixed, I still have the same issue. But on Manual Update, the sound issue seems to be resolved, but the camera no longer follows the player.

The best would probably be to set the “Update method” back to what it was.

Do not use PlayClipAtPoint. Instead, add a normal AudioSource to your pickups game objects Set the “Spatial Blend” to 2D. Play that AudioSource when a collision happens. That should hopefully fix the issue.

Okay, so now it won’t play at all. I’ve been playing around with things trying to figure out but essentially this is what I added to the code.

I created a variable and made a reference for the AudioSource in the Start function based on the instance of the specific object:

audioSource = gameObject.GetComponent<AudioSource>();

And I used this in the OnTriggerEnter2D function to play the sound:

audioSource.Play();

Is this the correct implementation or am I missing something? When I check the box to play the sound on Awake in the AudioSource component that will play. But when collecting the coin, it won’t.

That’s the correct implementation. It’s good that you tested the audio source in Awake. We now know that the implementation itself works.

Could it be that the coin game object gets destroyed? If so, the AudioSource gets destroyed along with it.

If that’s the case, you could call Destroy with a delay (second argument in the parentheses). And you could disable the SpriteRenderer and the Collider so the coin becomes invisible and “uncollectable” after it was “collected”.

That was the problem! It was getting destroyed. Following your advice straightened it out. I fixed it by disabling the SpriteRenderer and the Collider and then for good measure I created a new function to destroy the coin so that I could use the Invoke method and a half a second delay.

Everything works now as intended! Thanks for your help, Nina!

Good job! I’m glad you solved this problem. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms