Weird Rotation bug?

I was originally planning to share the video of this happening, but it ended up not working out right.

So, this is a little weird but I’ll try to keep it straight.

Before I tried to use Snagit to record what was happening:
If I had “Rocket ship” (my ship) selected in the hierarchy and then Played the game, the rotation speed was reasonable in game. It was easy to maneuver and control, etc.
If I had anything else highlighted in the hierarchy and then Played the game, the rotation speed was probably 3x faster than it had been previously.

I originally (a few lessons back) had added some lines of code to my script to use Time.deltaTime for rotation, but it slowed my rotation speed down to a crawl. I tried to use AddTorque and apply forces that way, but eventually I couldn’t get it to work right because of my inexperience and decided to just follow more closely to the lesson until Time.deltaTime gets brought up again.

So I thought I’d share this weird bug here, started up Snagit, went to record the game with “Rocket Ship” selected, and I cannot get it to play like it did previously. I tried selecting different items in the hierarchy, and now no matter what the rotation speed is pretty high. I guess at least now the game will be consistent, so I don’t really need to worry too much.

But has anyone else seen something like this or know what caused it? Not a big deal at this point, but I don’t want it hurting me down the line either.

Thank you! And sorry for the length of this post, lol.

Hi Billy,

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);
  }
}

You could refactor the code for the rotation accordingly.

Did this fix the issue?


See also:

1 Like

Hi Nina!

Thank you for the tip on the weird Unity bug. Unfortunately I’ve already moved on to the lesson where I am now able to adjust the rate of rotation in the inspector without having to edit the script, but everything does seem to be working just fine now.

But I will definitely remember this happening in case I experience something like it again! Experience is my favorite way to learn, haha.

I’m glad you found a solution. :slight_smile:

1 Like

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

Privacy & Terms