Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Using Timeline to plot a character's walk/run path

Discussion in 'Timeline' started by syscrusher, Jan 14, 2018.

  1. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    1,104
    Please forgive what should be a simple question, but I've been all over the tutorials and manual and haven't seen this topic covered.

    I am trying to get the Third Person character (Ethan) from the Standard Assets to simply walk a path based on a Timeline.

    So far I've been able to do this by having a generic empty GameObject animated with Timeline, and using that as the target of a NavigationAgent in the AI Third Person Character. is there a more direct method than this?

    All the tutorials show people walking their characters forward and back with the Timeline slider, but nobody seems to cover how to actually set up that character's object structure. What am I overlooking?

    Thanks!
     
  2. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    From the sound of it, the people you are talking about probably use rootmotion to let the animations drive the transform directly.

    Then they just setup a timeline with one iteration of the walk animation.
    You can set the loop mode of an animation in the timeline as well.
    That way, outside the valid range, it will repeat smoothly.

    Is that what you mean?
     
  3. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    1,104
    Ah, that might be the way it's done in the vids, then. I didn't think about looping the walk animation with root motion.

    Is there a way to go the other direction, when root motion is not in use? What I'm trying to do is to externally move the transform and then have the animation parameters follow. I have this working with a custom C# script using Curvy (a spline tool from the Asset Store) to drive the transform. For some reason, though, when I drive the same transform with Timeline there's no animation.

    Timeline also does some really strange things with local vs. absolute transforms, but one of the Unity folks told me to work around that with a parent object, which I'm doing.

    Thanks for the reply. I realize I'm probably not asking the question very well.
     
  4. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    1,104
    I think I figured out how I should have asked this. The question is, if I enable root motion and let it drive the transform, how do I use Timeline to drive the blend tree for the locomotion animation state? I suppose I could drive the animator parameters directly from Timeline curves -- is that the correct approach?
     
  5. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    If you're just aiming to make a cut-scene or movie clip or something that people wont interact with directly, then sure, that would be perfectly fine.

    As for your other question:
    driving animations indirectly just through you moving the transform is impossible. (without a script)

    You need some kind of code that sets the animator parameters (for blend trees or whatever).
    So some animation controller script that checks what the previous position was, what the current position is, calculate the delta, calculate the movement speed from that, and then set that movement speed on the animator.

    Keep in mind that this will likely yield pretty bad results (as in stuttering and whatnot) unless you really do it carefully.

    The whole concept is really only acceptable for movies and cutscenes where you can rely on things playing out exactly the same every time.

    For a game where a person is controlling a character directly you'd not even want to use root motion in the first place for many reasons.
     
    syscrusher likes this.
  6. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    1,104
    Understood, and thanks. That's the script I've created,which works when something other than Timeline is moving the transform. You're right -- the results are less than stellar, but okay for what I'm making (a movie render, not a game, and yes, everything will proceed the same every time).

    I think I may just be best staying with my navmesh solution. It has plenty of flaws, but it does give me obstacle avoidance if two NPCs cross paths. "Hello, Cinemachine...Let's make these shots tight enough not to show the foot slippage..."