Adding audio to asset bugs out the movement

Im trying to learn Unity3d from a tutorial. I have a rocket prefab where the rocket moves up when I click the space button, and in the tutorial next step is to put the audio source. But when I put the audio source, without changing anything else, the movement doesn’t work as well. As if the object became heavier (it works if i decrease the mass of my rigidbody). Why could this be and how can I fix this?

This is the code i have. Doesn’t matter if this code is added or not the problem persist if i comment it out too.

if (Input.GetKey(KeyCode.Space))
{
rigidBody.AddRelativeForce(Vector3.up);
if (!audioSource.isPlaying)
{
audioSource.Play();
}
}
else
{
audioSource.Stop();
}
Expected result is the speed of my rocket doesnt change. But it changes(slows down/ doesnt fly at all),
Im trying to learn Unity3d from a tutorial. I have a rocket prefab where the rocket moves up when I click the space button, and in the tutorial next step is to put the audio source. But when I put the audio source, without changing anything else, the movement doesn’t work as well. As if the object became heavier (it works if i decrease the mass of my rigidbody). Why could this be and how can I fix this?

This is the code i have. Doesn’t matter if this code is added or not the problem persist if i comment it out too.

if (Input.GetKey(KeyCode.Space))
{
rigidBody.AddRelativeForce(Vector3.up);
if (!audioSource.isPlaying)
{
audioSource.Play();
}
}
else
{
audioSource.Stop();
}
Expected result is the speed of my rocket doesnt change. But it changes(slows down/ doesnt fly at all)

It is hard to tell without the whole code (next time please include all the relevant code, like in what function is your code embedded (Update / FixedUpdate …)). But my guess is, that your code is in Update() and is framerate dependent. Adding audiosource can cause framerate drop and thus less force applied to your rocket. Moreover, I think you may have wrongly placed brackets: your “else” statement executes when you are not pressing space. Try this:

if (Input.GetKey(KeyCode.Space)) 
{
 rigidBody.AddRelativeForce(100*Vector3.up*Time.deltaTime);
 if (!audioSource.isPlaying)
 {
   audioSource.Play();
 } 
 else 
 { 
 audioSource.Stop(); 
 }
} 

I multiplied the force by 100, because Time.deltaTime tends to be very small, but you have to try what’s the best value. Best create public variable “strength”, multiply force by strength and adjust it in the inspector. Other option is you move your code to FixedUpdate() function, but only force application part, not the input detection. I guess this is a little bit complicated option for you right now. (And by the way I probably started learning Unity by the same tutorial and I spotted this same “mistake” they’ve made. It’s not really a mistake, it is there for simplicity reasons).