Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question [Animation C# Jobs] How to properly modify root motion in IAnimationJob.ProcessRootMotion()

Discussion in 'Animation' started by superkerokero, Sep 30, 2022.

  1. superkerokero

    superkerokero

    Joined:
    Dec 9, 2015
    Posts:
    6
    IAnimationJob provides a method called "ProcessRootMotion", as its name suggests, it's supposed to be used to process animation' s root motion.

    ProcessRootMotion() has AnimationStream as the parameter.
    AnimationStream has properties of "rootMotionPosition" and "rootMotionRotation", but these are READ_ONLY, meaning you can't modify them.
    In addition, AnimationStream provides "velocity" and "angularVelocity", which are supposed to be avatar's velocities. These are writable, but I can't figure out how to use them to modify root motion that comes with an animation.

    Example 1.
    The character and animation is taken from mixamo.com.
    In this case, the animation is "capoeira", which has root motion that moves the character around.
    Setup the character with custom animation c# job like this and modify the velocity and angular velocity to zero. The expected result would be that the character stops moving around.
    But character's trajectory changes to a straight line, still moving.

    Original animation:


    Set velocity and angularVelocity to zero:


    Code (CSharp):
    1.         public void ProcessRootMotion(AnimationStream stream)
    2.         {
    3.             stream.velocity = Vector3.zero;
    4.             stream.angularVelocity = Vector3.zero;
    5.         }
     
  2. superkerokero

    superkerokero

    Joined:
    Dec 9, 2015
    Posts:
    6
    Original animation gif:
     

    Attached Files:

  3. superkerokero

    superkerokero

    Joined:
    Dec 9, 2015
    Posts:
    6
    Set velocity and angularVelocity to zero:
     

    Attached Files:

unityunity