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. Dismiss Notice

Question Recording Position of Bone in Humanoid Animation

Discussion in 'Animation' started by darkwingfart, Aug 28, 2021.

  1. darkwingfart


    Oct 13, 2018
    I'm converting skinned mesh renderers into vertex animations. In order to do this I need to transform the parent object manually. I've successfully recorded the root motion. I tried doing the same for the head, but the motion does not match up. I'm preprocessing the animation to apply these transforms at runtime.

    My workflow for recording root motion is as follows.
    1) Animations are set with no baking.
    2) The animator is set to "Apply Root Motion".
    3) I record the position before and after after my predefined timestep, subtract, and offset my vertex animation parent by the change in position. I simply record the rotation quaternion and apply.

    I do this for every frame in my animation and record it to an indexed data structure.
    Code (CSharp):
    1. RootStartPosition = parent.transform.position;
    2. ...
    3. Vector3 rootEndPosition = Root.transform.position;
    4. Vector3 rootMovementVector = rootEndPosition - RootStartPosition;
    5. Quaternion rootEndRotation = Root.transform.rotation;
    6. Transforms[frame].RootPosition[i] = rootMovementVector;
    7. Transforms[frame].RootRotation[i] = rootEndRotation;

    My question is why does this same process not work for my head location? The head position follows reasonably closely but it drifts away, and the rotation is noticably off when rotation happens in the X axis.
    Is there something I'm missing?
  2. darkwingfart


    Oct 13, 2018
    I fixed the rotation issue. It was indeed a logic problem. I believe I can solve the head position issue by setting its localposition instead.