private float MotionMatch() { float newTime = Time.fixedTime; float timeClipRunning = newTime - timeSinceLastUpdate; AnimatorStateInfo animationInfo = anim.GetCurrentAnimatorStateInfo(0); //AnimatorClipInfo[] animationClip = anim.GetCurrentAnimatorClipInfo(0); var currentClip = mocapLoader.getClipAtIndex(currentClipIndex); float fn = 0; if (currentClip != null) { fn = currentClip.length * animationInfo.normalizedTime; } Debug.Log("last clip ran for " + timeClipRunning + " seconds, ending at frame " + (int)fn); currentFrameIndex = (int)fn; // skip this pose? var poseMatches = dbcon.diffIndexMatrix[currentClipIndex]; List <int> bestPoseMatches = poseMatches.Take(NumPoseMatch).ToList(); Debug.Log("best pose matches" + string.Join(",", bestPoseMatches)); // ignore pose cost for now, just match the best trajectory var nextTrajectory = pathReader.sample(newTime); int bestClipNumber = 0; int bestFrameNumber = 0; float bestTrajectoryCost = 1000000; for (int i = 0; i < bestPoseMatches.Count; i++) { int poseIndex = bestPoseMatches[i]; (int clipNumber, int frameNumber) = dbcon.belongsTo[poseIndex]; // change trajectory matrix later for edge case if (frameNumber > dbcon.trajectoryMatrix[clipNumber].Count - 1) { continue; } List <Point> trajectory = dbcon.trajectoryMatrix[clipNumber][frameNumber]; float trajectoryCost = pathReader.trajectoryDifference(nextTrajectory, trajectory); if (trajectoryCost < bestTrajectoryCost) { bestTrajectoryCost = trajectoryCost; bestClipNumber = clipNumber; bestFrameNumber = frameNumber; } } currentClipIndex = bestClipNumber; currentFrameIndex = bestFrameNumber; return(bestTrajectoryCost); }