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:
    43
    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!
     
    anone13 and koyodi like this.
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    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.
     
    Deleted User, anone13, koyodi and 3 others like this.
  3. jzzja

    jzzja

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

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    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:
    1,516
    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:
    144
    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:
    144
    (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:
    144
    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:
    1,516
    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:
    144
    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:
    250
    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??!
     
  12. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    how 4 year of timeline and we are at the same way ?
     
    rahulk1991 likes this.
  13. everett_unity760

    everett_unity760

    Joined:
    Oct 29, 2019
    Posts:
    1
    Where is this field in Unity 2019? I've been spending hours trying to get some floating text to the right position and I'm pretty sure this is what the blocker is, if someone could tell me where to find this field that would be great.
     
  14. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    The clip offset only shows up if the animation is animating the root transform. It is meant to offset the animation position, and doesn't apply otherwise.

    Instead, you can create an override track and keyframe the position/rotation you want.
     
  15. SamRock

    SamRock

    Joined:
    Sep 5, 2017
    Posts:
    250
    Is there a video that demonstrates this process? I am not able to get this to work! :(
     
  16. jcellswo

    jcellswo

    Joined:
    Aug 31, 2019
    Posts:
    2
    Same problem here. I am triggering a timeline using a collider trigger. I'm trying to get the timeline animations to start where they have been moved to in the scene. Are there any tutorials on this?
     
    SamRock likes this.
  17. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Sorry, I missed the earlier reply...

    Right click on the animation track, select Add Override Track. Move the clips to the override track.
    On the main track, hit the record button, then move the object where it should be in the scene or (0,0,0) if it should be set at runtime.

    On the main track, you should be able to then change the TrackOffsets to Apply Scene Offsets, which will have the timeline start at the current scene position.
     
    Rechronicle and SamRock like this.
  18. JoonglipK

    JoonglipK

    Joined:
    Feb 11, 2020
    Posts:
    1
    Is there a way you can make your object move to the starting position of the cutscene from your current position by Timeline? The character somewhat warps, and if I use Apply Scene Offsets, sometimes the movement won't match the environment.
     
  19. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    I assume you mean you want it to walk or similar to the starting position for the Timeline? I think you would have to do that yourself before starting the Timeline playing.

    I once made the animation move a "target" object and so made the character run/walk towards the target (speed was based on distance to the target), so I guess you could use that trick at the start of the timeline, but overall it was painful as scrubbing the timeline in the editor moved the target, not the character, so it would run all around the place as you scrubbed. It ended up more annoying than useful.
     
  20. Kbozz

    Kbozz

    Joined:
    Sep 6, 2019
    Posts:
    1
    Just diactive the boolean "Apply root motion" in your animator for some people that have this issue.
     
    keuwa likes this.