Search Unity

How to calculate future position from animation clip?

Discussion in 'Animation' started by dreaw131313, Aug 26, 2019.

  1. dreaw131313

    dreaw131313

    Joined:
    Jul 27, 2017
    Posts:
    1
    I try to write prototype of Motion Matching system. To calculate the cost needed to select the next animation needs to calculate the future position of the character. I totally don't know how to do it. I wrote a simple editor that retrieves data from animations such as position, rotation etc. My idea was to calculate position in the following way:

    1. int framCheckCount = checkSteps;
    2. int currentFrame = candidatePose.frameNumber + 1;
    3. int lastFrameIndex = framCheckCount + currentFrame;
    4. int gizmoPosCounter = 0;
    5. Vector3 fPos = transform.position;
    6. Quaternion fRot = transform.rotation;
    7. for (; currentFrame <lastFrameIndex; currentFrame ++)
    8. {
    9. if (currentFrame> mmAnim [clipIndex] .mm_ClipInfo.length - 1)
    10. {
    11. lastFrameIndex - = currentFrame;
    12. currentFrame = 0;
    13. }
    14. BoneData root = mmAnim [clipIndex] .mm_ClipInfo.frames [currentFrame] .rootInfo;
    15. fRot * = root.deltaRotation;
    16. fPos + = fRot * root.deltaPosition;
    17. gizmoPos [gizmoPosCounter] = fPos;
    18. gizmoPosCounter ++;
    19. }
    20. return fPos;
    21. }
    BoneData is my own class where it stores deltaRotation, deltaPosition, position rotation itp. Candidate pose is a object of class which holds info about all bones. When i use this method, my future position is incorrect. Any ideas on how to get a future position from animation. Maybe there is a simpler way to calculate future position based on animation?

    Add comment
     
    Raisito likes this.