Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

I love animating with the timeline, but. . .

Discussion in 'Timeline' started by Eidrog, Mar 30, 2018.

  1. Eidrog

    Eidrog

    Joined:
    Nov 12, 2015
    Posts:
    3
    I've been playing with Timeline for the last two days, and I'm loving it. Making cutscenes feels way nicer when you can preview all the moving parts with one timeline. However, I'm having a lot of difficulty positioning my objects where I want them to, and moving them in the right direction when I use Timeline to record the object's movement.

    For Example:

    I make a scene with a red carpet. The red carpet starts at x:5 and ends at x:-5.



    I place my character in the scene, like so:
    Position: x: 0, y:0, z:0
    Rotation: x: 0, y: 0, z:0



    Next I move my character to where I want him positioned in my scene.
    Position: x: 6, y:0, z:0
    Rotation: x: 0, y: -90, z:0



    There we go. Now, I want to create a "cutscene," where he's going to walk down the red carpet. :)

    I add a Timeline to the scene, and start recording his position. I set a keyframe at frame 1.
    Position: x: 6, y:0, z:0



    And another keyframe at Frame 120 (2 seconds of animation)
    Position: x: -6, y:0, z:0



    When I hit play in the Timeline Preview I get the desired animation:



    But. . . when I watch this cutscene during a Gameplay Test, I get a different animation. My character pops to the origin point of the scene, and moves in the wrong direction.



    Thinking this is a bit odd :confused: I go to the Animation Editor to inspect the recorded animation, maybe I can trouble-shoot this oddity. (btw, I love that we can fine tune-these animations in the Animation Editor!)

    I open the Animation editor expecting to see animation on my character's x position. But the line is completely flat.



    So I look at other curves and notice the animation was keyed on my character's z position.



    Ah ha! So it looks like the recorded animation captured local co-ordinates relative to my character, rather than global co-ordinates relative to my scene. I was expecting the animation to be:
    X: 6 tweening to X: -6
    but instead I got
    Z: 0 tweening to Z: 12

    But the confusing thing for me is, these local co-ordinates appear to be getting treated like global co-ordinates when it comes time to playing the cutscene during gameplay. As indeed my character is popping to Z: 0 and moving to Z: 12.

    Since I've only been using timeline animation for 2 days I'm probably missing something obvious, but this has me blocked. Any help getting my character animating correctly during a gameplay cutscene would be greatly appreciated! :D

    Update: I noticed when I add an Animator Controller on my character and toggle on Apply Root Motion, he moves as expected during gameplay. . . but. . . if I play the cutscene again, rather than jumping back to his start position and walking across the carpet, he keeps moving forward, further away from the carpet.
     
  2. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,643
    Root motion will apply animations relative to their current position. You have to generate motion curves on the animation file for this.

    Regular animation will snap them to the start position of the animation. This might change if the object has a parent, and the parent has moved.
     
  3. Eidrog

    Eidrog

    Joined:
    Nov 12, 2015
    Posts:
    3
    Yeah, that seems to be the problem. :(

    Is there any way to record with global coordinates while placing keys in the Timeline? That would be perfect and fix this problem. Otherwise, I suppose I could encapsulate each of my characters inside a 'position' game object like so:

    KingCube_Position Position/Rotation: x: 0, y:0, z:0
    ╚ KingCube Position/Rotation: x: 0, y:0, z:0

    . . . and. . .

    KingCube_Position ← add an Animator Controller that handles how the character is positioned / rotated in the scene.
    ╚ KingCube ← add an Animator Controller that handles what pose or animation loop the character is playing.

    This way I can effectively key my character's placement in the scene with global coordinates since the 'KingCube_Position' gameobject is placed at x: 0, y:0, z:0
     
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,098
    bump, need this too
     
  5. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    If the animator has a controller attached, it will start relative to it's current position (in PlayMode). If there is no controller attached, it will start in global coordinates. (i.e. PlayMode and Editor will always match)

    When recording, the recording is done relative to it's current position/rotation, so if you are looking to record with absolute coordinates have your object at the origin with no rotation when you start recording. The initial rotation and position is copied and becomes the initial offset. You can also manage the offsets in the inspector of the Track using the Recorded Offsets fields.

    upload_2018-4-5_9-54-45.png


    The catch here is initial offsets are ignored in playmode if there is a controller attached to the animator (because it's starting from it's current position).

    Admittedly, this is confusing, and we are in the process of improving this so that the track can determine whether to play in absolute or relative coordinates, instead of the presence of a controller determining it.

    I hope this clears it up a bit, and explains the behaviour you are seeing.
     
    dom_cobb_22 and Alverik like this.
  6. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,098
    Thankyou, is there any area of code we could edit ourselves if not wanting to wait until end of the year for this to be usable in most use cases without headaches?

    really want to use timeline since 2017 and its still not really a decent workflow because of this. More than happy to do the code myself until the official fix comes out.

    Any pointers on where to delve into to find the stuff controlling this would be great!
     
  7. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    It depends a bit on what you are trying to change. The offsets are available through the API, but the starting position behaviour is done by the animator itself, so that is a bit tricky to work around.
     
unityunity