Search Unity

Animation Goes Crazy When I make keys

Discussion in 'Animation' started by JungleStudios, Jun 15, 2016.

  1. JungleStudios

    JungleStudios

    Joined:
    Jun 15, 2016
    Posts:
    4
    When I'm trying to animate an object, i start with frame 1 blank, then i go to the 0.10 mark and slight move it, then when i play it it goes super crazy and i just want to know how to fix it??
     
  2. SamElTerrible

    SamElTerrible

    Joined:
    Jul 6, 2015
    Posts:
    2
    Hi, I ran into a similar problem recently and here's how I fixed it. I noticed that the "going crazy" was due to adding a rotation to the object in the animation; specifically, when the rotation was in negative degrees. For example, if you set the rotation in the x axis as -10, unity will change it to 350, so the animation will go to the specified position the "long way", causing the craziness.

    To solve this, go into the curves tab in the animation window and find the key with the wrongly converted number (in this case, it would be the key with the 350 value under the x axis rotation). Right click on the key and select edit key. Then, change the value from 350 to -10. This time, Unity won't change the number and your animation will work properly. Do this for all the keys whose values are being wrongfully converted.
     
  3. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Hi guys, can you tell us in which version you are getting this?

    it look like a bug we did fix a few week ago
     
  4. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
  5. SamElTerrible

    SamElTerrible

    Joined:
    Jul 6, 2015
    Posts:
    2
    I'm running 5.3.5, so I guess I'll have to upgrade and see if that fixes it
     
  6. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    If your bug is still happening in 5.3.6, please file a bug. This is a serious issue, and I'd like to make sure it stays fixed.
     
  7. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    If this is not filed yet I can confirm it is still happening in 5.4.0f3 as well. I am copying and pasting rotations via script while editing keys and it doesn't go into the negative range. I have to manually go in and change all the keys in the curves editor.

    RotationBug.gif
     
  8. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    @playemgames
    Please file a bug with your script. The Animation Window does quite a few propgrammatic backflips to deal with the fact that the transform doesn't actually store Euler angles, only quaternions. Interacting with the recording by script (as opposed to creating your own curves) is quite finnicky, so I'd like to take a look at your script to see exactly is going wrong.
     
  9. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Sure thing will submit one later today.
     
  10. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    @DavidGeoffroy I privated messaged you the case number, let me know if you have any questions. I also found a bug where if you copy and paste rotation animation keys between animation clips they are always Quaternion Interpolation neglecting the source interpolation of the keys.
     
  11. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    Did this get looked at yet? Really want this fixed so I don't have to double back and manually set keys to negative all the time in the curve editor.
     
  12. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Transform.localEulerAngles has been changed so the behaviour is coherent between runtime and editor, and will always directly use the Quaternion to set/get angles (what was happening in standalone). This also means that transform.localEulerAngles and transform.localRotation.eulerAngles now return the same value / have the same behaviour.

    This also let us fix a bunch of old bugs where when you were rotating an object, rotation values would slowly creep up or jump in weird ways.

    We understand that this can be problematic for users who have their own custom keyframing workflows, and we're adding new accessors to make this work properly.

    In the meantime, you can use methods in the file I've attached to do the same thing we do in the AnimationWindow:

    You need to do something like:
    transform.localEulerAngles = yourAngles; //This sets the rotation Quaternion on the GameObject
    LocalEulerHint.SetLocalEulerAngleHintOnGameObject(transform.gameObject, yourAngles) //This tells the inspector (and the AnimationWindow) how many rotations to show for this angle


    When getting the angle, you don't need both, you can use LocalEulerHint.GetLocalEulerAngleHintFromGameObject(transform.gameObject)
     

    Attached Files:

  13. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    This is great news! Hopefully all my animation rotation woes will disappear soon then. Are these functions preliminary and undocumented? This explains a lot of discrepancies in the rotations I was having in my animations as I was creating them in Unity.

    So if I am going to use a function to set the rotation key or curve in the Animation Window I would use:

    LocalEulerAngleHint.SetLocalEulerAngleHintOnGameObject(transform.gameObject, transform.localEulerAngles);

    This should match up with what I see in the inspector correct?

    EDIT: Actually I see you are referring to the attached script, I imagine this has to be placed somewhere and then used to make the expected behaviors to happen. I also tried to use it and getting a "ArgumentException: failed to convert parameters" error when I test. What version has the new fixes to the rotations?
     
    Last edited: Sep 25, 2016
  14. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Oops. I implemented this on the latest version, and I was in a hurry, and forgot to test it in earlier versions.

    What version are you on?
     
  15. playemgames

    playemgames

    Joined:
    Apr 30, 2009
    Posts:
    438
    5.4.1p1
     
  16. playback2424

    playback2424

    Joined:
    Mar 13, 2019
    Posts:
    1
    I have same problem .... I set rotation to 90 degrees in my animation ... it automatically changes to some random number and animation goes crazy
     
  17. gianni22

    gianni22

    Joined:
    Apr 26, 2015
    Posts:
    5
    2018.3 tambien lo hace.
     
  18. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    This thread is very old.
    If you have bugs related to this, please file a bug. It's unlikely to be the same bug as this one