How to calculate future position of animated object based on root motion animation?
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:
int framCheckCount = checkSteps;
int currentFrame = candidatePose.frameNumber + 1;
int lastFrameIndex = framCheckCount + currentFrame;
int gizmoPosCounter = 0;
Vector3 fPos = transform.position;
Quaternion fRot = transform.rotation;
for (; currentFrame <lastFrameIndex; currentFrame ++)
{
if (currentFrame> mmAnim [clipIndex] .mm_ClipInfo.length - 1)
{
lastFrameIndex - = currentFrame;
currentFrame = 0;
}
BoneData root = mmAnim [clipIndex] .mm_ClipInfo.frames [currentFrame] .rootInfo;
fRot * = root.deltaRotation;
fPos + = fRot * root.deltaPosition;
gizmoPos [gizmoPosCounter] = fPos;
gizmoPosCounter ++;
}
return fPos;
}
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?
Your answer
Follow this Question
Related Questions
Animations unwanted movement and rotation after updating 0 Answers
Animation changes constantly reset themselves. 1 Answer
Sprite rotation clip & ending position 0 Answers
Move 2 objects as one 0 Answers
Car Controls without physics. 1 Answer