My rocket have some problem with movement after the audiosource sound addition

Hi. I am watching the 3d unity course, and i have problems with my rocket on the 2nd chapter.

After the sound that i choose on freesound, the rocket gets heavier and slow. I try with ogg, wav and mp3 format, with differents sounds. But it’s not solved :frowning:

If i press “A” or “D”, the rocket falls.

This guy have the same problem on his project:

https://forum.unity.com/threads/audiosource-is-messing-up-my-character.908021/

1 Like

Hi Pedro,

There is a strange bug in Unity which prevents the rocket from flying properly when it is selected in the Hierarchy. Try to select something else and click into the game window once to set Unity’s focus on the game window again.

If that didn’t work, try to remove Time.deltaTime from the AddRelativeForce method. Alternatively, test this potential solution in the Rocket.cs:

bool isThrusting = false;

private void RespondToThrustInput()
{
  isThrusting = Input.GetKey(KeyCode.Space);

  if (isThrusting)
  {
    ApplyThrust();
  }
  else
  {
    audioSource.Stop();
    mainEngineParticles.Stop();
  }
}

private void ApplyThrust()
{
  if (!audioSource.isPlaying)
  {
    audioSource.PlayOneShot(mainEngine);
  }

  mainEngineParticles.Play();
}

private void FixedUpdate()
{
  if (isThrusting)
  {
    rigidBody.AddRelativeForce(Vector3.up * mainThrust, ForceMode.Acceleration);
  }
}

Did this fix the issue?

If it does and if you are experiencing issues with the rotation, you could apply this concept to the rotation code.


See also:

Hi Nina.

Thank you so much, i selected another object while i was using play mode and works great.

SOLVED :slight_smile:

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

Privacy & Terms