Turn thruster sound issues and fix

So I took up Rick’s idea of adding left and right thruster sounds and found that there was an issue with the current single AudioSource.

When I used the same kind of code as the main thruster I found that I heard just a buzz sound for thruster sounds and no sound for my booster, unless I pushed space and A or D at the same time and then they would seem to play correctly.

I fixed it by putting a second AudioSource component on my rocket. Turns out that my Stop() in the rotation code interferes with my boost sound, and the Stop() in my boost code interferes with the thruster sounds in the rotation code.

I had to use GetComponents which gets an array of AudioSources then I put them into AudioSourceA and AudioSourceB and used each one separately for thrusters and booster. Then everything just worked.

1 Like

I ran into the same problem myself when I tried adding sound to my side thrusters. While I didn’t use an array (didn’t really know how to use it), I ended up fixing my problem by removing audioSource.Stop() from my side thruster method. And while the solution’s not perfect (it leaves my sound vulnerable to repetition), I found it to be good enough. Oddly enough, this still left me with some weird bugs that remain to be fixed.

Same here.
I gave up on trying to do it all within one script as its evidently tricky if Possible.
But at this stage I went maybe sloppy way but it definitely work with no issues.
Ive created an Empty Object within rocket prefab. Created new script sololely for side thruster noises. OnKeyDown activate OnKeyUp cut off. Slapped it on Empty.
Took me since yesterday to think of it.
Moving on!
Done :slight_smile:

Did my own implementation of this today. In the movement.cs script, added
[SerializeField] AudioSource sideThrustAudioSource; (serialize to expose it to inspector)

Go to your project tab, and then find the rocketship in the hierarchy, and select it.
In the inspector, add Component ->Audio-> AudioSource to add a new one. Use the mouse to left click on the text at the top of that new Audio Source and drag it up into the exposed audio source you created.

Now in your side thruster code, you can us sideThrustAudioSource.PlayOneShot() just like you did the audioSource you are using for your main thruster.

something like this:

if(Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))

    {

        //apply effects, then apply visible rotation

        if(!sideThrustAudioSource.isPlaying)

        {

            sideThrustAudioSource.PlayOneShot(sideThrustSound);

        }

        if(!rightParticle.isPlaying)

        {

            //we guard against both playing thusly

            leftParticle.Stop();

            rightParticle.Play();

        }

        ApplyRotation(1);

       

    }

    else if(Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))

    {

        //apply effects, then apply visible rotation

        if(!sideThrustAudioSource.isPlaying)

        {

            sideThrustAudioSource.PlayOneShot(sideThrustSound);

        }

        if(!leftParticle.isPlaying)

        {

            //we guard against both playing thusly

            rightParticle.Stop();

            leftParticle.Play();

        }

        ApplyRotation(-1);

        //leftParticle.Play();

    }else

    {

        sideThrustAudioSource.Stop(); 

        rightParticle.Stop();

        leftParticle.Stop();

    }

}

private void ApplyRotation(int sign)

{

    playerRb.freezeRotation = true;

    transform.Rotate(-Vector3.up * rotateForce * Time.deltaTime * sign);

    playerRb.freezeRotation = false;

}

Privacy & Terms