Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How can I animate/blend from a state between two poses to a third pose?

Discussion in 'Animation' started by kritoa, Jul 23, 2017.

  1. kritoa

    kritoa

    Joined:
    Apr 21, 2017
    Posts:
    60
    I'm new to Unity animation and I just want to make sure this is possible before I spend a ton of time making animation clips in my animation program.

    Say I have 3 poses for a hand model (this is a VR project): hand open, hand closed, hand pointed, and that I have an animation clip for smoothly transitioning between hand open and hand closed. So I can tell the AnimationState to go to time 0 and the hand will be open, time 1 and the hand is closed, and anywhere in between to get the intermediate positions.

    Whatever position between open and closed the hand is in, I'd like to be able to go straight from that to "hand pointed". That is, I'd like to be able trigger my "hand pointed" at any time and be able to go from "halfway between hand open and hand closed" to "hand pointed".

    Is this possible, and what animations do I need to make?

    Right now I have a clip that goes from "hand open" to "hand closed" and by changing the AnimationState.time I can get whatever intermediate position I'd like.

    If I just have a second clip that goes from "hand open" to "hand pointed", is there some stuff I can do with blending or something like that so I can animate from that intermediate position to hand pointed without first transitioning towards "hand open" or "hand closed"?
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    This is commonly called pose to pose animation.
    I think you can do this in Unity without creating animations that transition from one pose to another. But I have not done it before so I can't say for sure.

    This is a simple test to perform and the answers you seek will be provided by doing it.
     
  3. kritoa

    kritoa

    Joined:
    Apr 21, 2017
    Posts:
    60
    It turned out that you can do it, though there were a few pitfalls. The relevant function is Animation.CrossFade and you can simply blend from one animation (or pose if you put the speed at zero or are clamped at the end or beginning of a clip) to another.

    The pitfall that made it fail for no discernible reason was that the crossfade didn't work if no animations are currently playing, which was always the case when I was blending from a static pose at the end of another clip. The fix is to change all the animation clips' wrap mode to... I forget what the option was but something like "extend forever" or "freeze forever" or something like that. Then the animation is considered "still playing" after the clip finishes and the crossfade works correctly.
     
    theANMATOR2b likes this.
  4. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Glad you found the solution!
    Another option might be to export a 1 frame animation (which is essentially one non-animated pose) rather than editing the time. - Again - I've not done this - but it might be a better option to test out.
     
  5. kritoa

    kritoa

    Joined:
    Apr 21, 2017
    Posts:
    60
    I may have been a little unclear - to hold a pose at the end of a clip, you don't need to edit the time or anything like that - you just set the wrap mode to ClampForever and when the animation reaches the end of the clip it will freeze there even as the animation is considered "still running" so that it can be crossfaded. So you can avoid the 1 frame looping animation.

    The only time editing I am doing is because I have one animation clip that represents the animated change between two poses, but isn't meant to represent an actual action that takes place over time. e.g. if you have two poses (say, open hand and close hand) and I'd set the animation clip time to be the value of the analog trigger of my controller.
     
    theANMATOR2b likes this.