Search Unity

Get estimate of animation clip's root motion velocity?

Discussion in 'Animation' started by hungrybelome, May 8, 2019.

  1. hungrybelome

    hungrybelome

    Joined:
    Dec 31, 2014
    Posts:
    336
    Hi,

    I am disabling a unit's animator when they are off screen. When their animator is enabled, their movement is driven by their walk animation clip's root motion. So when their animator is disabled, I need to manually move their transform using an estimate of their walk animation's root motion, in order to keep a consistent move speed.

    Any advice on how I can get any sort of velocity data from an animation clip's root motion?

    Thanks!
     
    Novack likes this.
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    If an estimate is good enough, the AnimationClip.averageSpeed should do it (the name is wrong, it's a velocity vector, not just a single speed value).
     
    fuser, Baste and hungrybelome like this.
  3. hungrybelome

    hungrybelome

    Joined:
    Dec 31, 2014
    Posts:
    336
    Sweet, thank you! That property seems to be missing from https://docs.unity3d.com/ScriptReference/AnimationClip.html, so I wasn't aware of it. It seems to work perfectly! Thanks!
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Yeah, it's inherited from the Motion class which for some reason doesn't have any of its members documented.
     
  5. XGurem

    XGurem

    Joined:
    Dec 5, 2018
    Posts:
    9
    AnimationClip.averageSpeed doesn't pop up for me so I did some random typing and stumbled on anim.velocity(anim being what I set my animator's name as in my script). Would this also work cuz i'm using root motion for my movement and would like my aerial controls to inherit the current movement speed;
     
    SirGhoul likes this.