Unity Project Rocket Boost trouble

Hi,

I recently finished Project Rocket Boost section of the course Complete C# Unity Game Developer 3D.

I made a few tweaks but nothing significant before I tried to build and run in WebGL.

Once it was finished and ready to play on WebGL the rockets thrust just didn’t work enough to get it to take off. Everything else worked fine. Strange thing is that when I test the game on Unity the boost works perfectly.

Can anybody help me out?

Kind regards,

Jason Akeroyd

1 Like

Hi @JaYs0N,

Welcome to our community! :slight_smile:

There is a strange bug in Unity which prevents the rocket from flying 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,

Thankyou for the quick response. So after looking at what you advised to do and my code. It seemed different, however, I tried to implement it as best I could and see if it made a difference. All it did was cause the rocket to now not move properly in actual unity.

I tried everything then figured it can’t be anything wrong with code as its working fine on editor. Then noticed that the mainThrust was set to 2 so I increased that to 10 for one level and clicked to build and run. It now thrusts fine and works as intended.

There is still alot I would like to come back and change with this game as I get further into the course. I think one step would be to clean my code and make sure to always check the inspector and unity first not just my code haha.

This issue is now resolved and I’m in the process of uploading it.

Kind regards,

Jason Akeroyd

Good job. I’m glad you found the problem. :slight_smile:

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

Privacy & Terms