Search Unity

how to use animation.sample?

Discussion in 'Scripting' started by kritter, Jan 23, 2010.

  1. kritter

    kritter

    Joined:
    Jan 23, 2010
    Posts:
    7
    okay, so i've seen a few posts on this topic, but they always end with, "oh i figured it out", and no explanation how. i'm trying to get a char to recover from ragdoll. i can copy all the transforms from the ragdoll to the instantiated character, but can't figure out how to lerp to the beginning of an animation. everything i try just makes them snap directly to the animation. i believe i need to use mathf.LerpAngle, but don't know how to sample the transforms for the animation frame i need? thanks in advance for any help.
     
  2. Vimalakirti

    Vimalakirti

    Joined:
    Oct 12, 2009
    Posts:
    755
  3. kritter

    kritter

    Joined:
    Jan 23, 2010
    Posts:
    7
    animation.CrossFade was actually the first approach i tried. it snaps directly to the first frame even with a time variable. I believe this is because it tries to blend from the current animation. there is no current animation however, because it was just instantiated and posed. I'm gonna try to use additive mode and manually blend it in, but if anyone has a better solution, i'd love to hear it. :)
     
  4. mcwind

    mcwind

    Joined:
    Feb 7, 2011
    Posts:
    10
    Hi Kritter, I guess you must not had assigned the weight the clip you want fade in. Like this:
    ------------
    using UnityEngine;
    using System.Collections;

    public class example : MonoBehaviour {
    public void Awake() {
    animation["MyClip"].time = 2.0F;
    animation["MyClip"].enabled = true;
    animation["MyClip"].weight = 1.0; //if you don't assign a value,unity takes it as zero so the Sample() function has no effect !!
    animation.Sample();
    animation["MyClip"].enabled = false;
    }
    }
    ------------------
    If sample() goes well, it would take the char to the animation state you refer,the you get what you need.
     
    Spaniel likes this.
  5. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    I had this issue recently. It sounds like you want to use Animation.Blend instead of Crossfade