Search Unity

Rigidbody MoveRotation/angularVelocity stopped working!

Discussion in 'Physics' started by Plystire, Mar 14, 2018.

  1. Plystire

    Plystire

    Joined:
    Oct 30, 2016
    Posts:
    142
    I pulled out a project I last worked on some time last year. I believe it used Unity 5.5, but I have since updated to 2017.3.1f1

    When I launched the game in Unity, I noticed that my weapon wasn't rotated properly. In fact, it was facing straight Z+

    I looked into the code and found where it's suppose to rotate:
    Code (csharp):
    1.  
    2. if (target)
    3.         {
    4.             rig.velocity += movementPID.Update(target.position, transform.position, Time.fixedDeltaTime);
    5.             target.LookAt(physicalOrbitalRigs[0].transform.position);
    6.             //rig.angularVelocity += rotationPID.UpdateAngularVelocity(target.rotation, transform.rotation, Time.fixedDeltaTime);
    7.             rig.MoveRotation(target.rotation);
    8.         }
    9.  
    (Note, the angularVelocity line also produces no rotation)

    Looks simple enough... but here's where it gets dumb.

    I put a breakpoint on rig.MoveRotation and let the game run to it. Target.rotation is a valid rotation, that's not the rig's rotation. Upon stepping over the line, the rig's rotation has updated to the target's rotation...
    Nothing seems to be out of order here.

    I stop debugging and let the game continue to run. The object is not rotating..... but it has rotated slightly. I note the values of the object's rotation in the inspector. (It's non-zero, but unchanging)
    I return to the code and start debugging again, letting the game hit the breakpoint. I see the rig's rotation is the same as when I last looked before running it again. The target's rotation is a new value... stepping over MoveRotation updates the rig's rotation! I step through several more loops to ensure the rotation consistently updates. And it does. Every frame, the rotation is a new value.
    Stop debugging, and look back in the Editor. The object's rotation is unchanging again, but has a new value!


    What is going on?! I've tried working around this damn bug, but it's not even consistent between runtime and stepping through line-by-line! :(

    Keep in mind, this code used to work! How did something so simple in the engine become so broken? Is it because I let Unity update my old project?
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Is that code in Update or FixedUpdate?

    Since 2017.2 some non-conventional techniques, such as calling some methods from Update instead of FixedUpdate, seem to behave in a different way.

    You may try with Unity 2017.1.2 as well. Physics here is mostly the same as in 5.x.
     
    Plystire likes this.
  3. Plystire

    Plystire

    Joined:
    Oct 30, 2016
    Posts:
    142
    Sorry, I intended to mention that it was in FixedUpdate, but apparently forgot.

    I'll give 1.2 a shot, thanks.
     
  4. Plystire

    Plystire

    Joined:
    Oct 30, 2016
    Posts:
    142
    Downgrading to 2017.1.2f1 did the trick. That fixed the rigidbody rotation updates. Then I had to replace lost tags/layers ...

    Thanks for the suggestion! :D
     
    Edy likes this.