Search Unity

Setting animated objects transform to current position

Discussion in 'Timeline' started by jzzja, Mar 17, 2019.

  1. jzzja

    jzzja

    Joined:
    Sep 28, 2017
    Posts:
    37
    I've just started looking into timeline and cinemachine and I'm very impressed. I want to start by creating some in-game animation sequences. I've created a simple sequence and it works fine - the player moves into a collider which then triggers a timeline sequence, the sequence performs some animations on the player.

    The problem I have is that the animation uses the transform positions of the player object from when I originally made the animation, so when the player moves about and goes into the collider, the player then teleports to the fixed animation position. What I want is for the animation to use the current player position which could be anything and not the fixed positions in the animation sequence. Would I need to do this using a C# script? thanks!
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    883
    On the animation track, you can change the Offset Mode to Use Scene Offsets. That will make the track play relative to the current position, as opposed to a fixed location.
     
    jzzja likes this.
  3. jzzja

    jzzja

    Joined:
    Sep 28, 2017
    Posts:
    37
    Thanks very much
     
  4. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    142
    I'm having trouble with this as the animation I have chosen seems to rotate the main character 90* along the Y (up) axis. If I try to rotate the character's transform, the animation overrides this. If I have animation that is created, say, at origin and looking down the z axis, but the character is arbitrarily rotated in the scene, how do I get the animation to play, not only from the character's correct position in the scene, using scene offsets, but the rotation as well?
     
  5. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    883
    The offsets apply both transform and rotation. They should both be played relative to the current scene position when using Scene Offsets. If you don't want the rotation to be relative to the scene, you will have to reset just the rotation prior to playing the timeline.
     
  6. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    142
    Odd.

    Here's the sequence of events:

    Original Position:
    OriginalPose.png

    Original Transform:
    OriginalTransform.png

    Position on Play:
    PositionOnPlay.png


    Transform on Play:
    TransformOnPlay.png
     
  7. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    142
    (Due to image limit, this continues!)

    Reset the transform (while the playhead is IN the animation):
    ResetPose.png

    And check the Transform:
    ResetTransform.png

    Advance one frame and the animation takes over again:
    PositionResturnsOnContinue.png

    And the transform:
    PlayAfterCorrectionTransform.png
     
  8. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    142
    Now, this Rotation value seems INHERENT in the animation. It seems that the animation is facing 90* to the right and even though my model is facing down the Z-Axis the animation is forcing it to face down the X-Axis.

    I've tried a few things like: Trimming the head of the animation, just in case there was a frame of the character facing forward and then the next frame was facing right, but even with the animation trimmed and the character adjusted to face down the Z, as soon as I move the playhead, the character faces down the X.

    :-/

    Just to make sure, here is the setting:
    3facef96133e24f7e9d34d1e4d0dff7b.png

    If I set the Track Offsets to Transform Offsets; the animation behaves exactly the same (facing 90* out), just in a different location.

    Unchecking "Apply Root Motion" from the animator does nothing either...

    I'm baffled.
     
  9. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    883
    The clip itself also has offsets, try setting it's offsets to the inverse of the initial rotation. (e.g. 0, -83, 0)
     
  10. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    142
    This?
    8eea00cb65c5f9e2a9bc0a525a3c801b.png

    Yeah, I found that last night.

    I put in -90 so remove the +90 orientation. This solved the immediate problem, but then it means that I have to manually remove that value from the following clip when I use "Match Offset to Previous Clip"; but it is a work around.

    Thanks for all the help!
     
  11. SamRock

    SamRock

    Joined:
    Sep 5, 2017
    Posts:
    78
    Hi @seant_unity is there an updated documentation or video tutorial to use offsets to control the object's position? I am having really tough time figuring out what to use - Tranform Offset or Scene Offset!!

    Here is what I am trying to achieve :
    I am trying to create a Cutscene where my character starts at a particular position, then the Cinemachine Cam kicks to go around the map a bit and finally end at a fix position. As this point, I want my character to appear at the new camera location (as if he walked all the way up here while the camera was panning around the map). But this is not working! How do I achieve this??!