Search Unity

Question Timeline rotation - best practices?

Discussion in 'Timeline' started by metaphysician, Feb 13, 2023.

  1. metaphysician

    metaphysician

    Joined:
    May 29, 2012
    Posts:
    190
    hey folks i'm in Unity 2021.3 LTS trying to rotate an object 360 degrees in Y rotation in a couple of ways and both ways seem to create a substantial glitch going from 359.99 to 0.

    the first way is that i'm using an Animator to drive a script float value to manually drive a rotation value on a script using Quaternion.LookRotation and transform.RotateAround. after putting in the keyframes on an Animation track, that produced the flicker going from 359.99 to 0.

    so, troubleshooting this some more i decided to test whether the issue was related to my script or to Timeline itself. so i just created a parent child object pair, moved the child outwards from the rotating object and rotated the parent using an Animator and Animation and keyframes. after quite a bit of finagling due to Timeline wanting to auto find the shortest rotational distance the result was unfortunately the same - a slight flicker just as the 259.99 value flipped to 0.

    so it seems that Timeline does not like rotation values to 'flip over' from max back to min in one frame without creating a glitch in the process. that being said is there a best practice for achieving this in Timeline, especially since i (for reasons) need to drive the rotated objects by script values? i think it might be possible to increase rotation range to something like 1800 which would give 5 rotations before having to flip over, but it seems the flipover glitch would still be an issue. any assistance or advice appreciated!
     
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,444
    Yeah, it's a massive shortcoming in Timeline. If everything is an evaluatable functional curve, then for any given T value along the curve, there can only be one answer. Thus, you can never snap from -180 to +180 in zero time, you always have a chance of being evaluated at a T which is in between the -180 keyframe and the +180 keyframe, and get some weird in-between value.

    One approach that just occurred to me, if you only need something between 360º and 719º rotation, is to have a hidden empty between the other objects. Rotate the empty and the child so their combined rate looks right. Now the combination of them can rotate farther before any discontinuities. But that's not a solution for propeller blades, etc., which spin multiple times.

    The better approach would be to keyframe a parameter on a special Timeline/Playable component that drives a rotational speed, instead of the actual rotation.
     
    metaphysician likes this.
  3. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    Just a suggestion: Have you tried editing the properties on the Animation Clip directly? For example, I created an animation track, recorded the start and end Y rotations of 0 and 720 using the inspector and recorded those values - and yes, it set it to zero. So instead, I opened the Animation window (double clicked on the Timeline track to open the animation window) and expanded the Rotation property and explicitly set it to 720 at the end point. Scrubbing the timeline then went from zero to 720, rotating the character twice. So you may be able to use the Animation window to get better control.

    upload_2023-2-13_18-53-24.png

    Also, I assume you know you have curves for the animation, so you need to take them into account if you want constant rotation speed. The above shows it starts and ends slow - if you put one after the other with different curves you can get some funny results.
     
    metaphysician likes this.
  4. metaphysician

    metaphysician

    Joined:
    May 29, 2012
    Posts:
    190
    thanks for the responses! to clarify i can't directly rotate an object like i covered in the second example, because there are multiple Timeline assets and groupings of parents and children will all change as to which is rotating and which is not. i'd prefer keeping the objects as they are and use the script to rotate them like in the first example.

    but i can create an Animation clip and it is certainly possible to over-rotate/multi-rotate the objects in question though i'm not yet 100% sure if it works if i'm driving a float parameter that drives the angle of the master rotation object. this is somewhat similar to @akent99 's suggestion. in this specific case the rotation speed can be slow, like 10-15 seconds per rotation. so that leaves some room. i did in fact edit both examples in the Animation window to make sure i had the keyframing correct on the crossover.

    in response to @halley i have experimented with auto rotation in another section of the app and it is definitely smooth -it's a bit tricky to line things up so that a specific angle hits at a specific time though which is why i was hoping i could just manually rotate by adjusting angle on the script with a couple of keyframes instead of guessing back and forth. but auto rotation could work.

    i'll look into over rotation and see if the scripts allow this option. thanks!
     
  5. metaphysician

    metaphysician

    Joined:
    May 29, 2012
    Posts:
    190
    Update: over rotation works just fine as long as you don't mind ludicrously high animation values.