# Manually Sample And Interpolate Last To First Keyframes

Hey guys… i am almost done all the functionality for my animation system. I need to be able manually sample animation frames and on the last frame interpolate from the last frame to the first frame on looping. What is the best way to do that… I know lerping, but for how long… what are the gradient values to use LERP from the last from to the first frame…

Pinging the crew @Deltakosh, @sebavan, @Pryme8, @PirateJC, @Wingnut and @Evgeni_Popov

I would guess that for a looped animation, if this animation has a certain duration `t_anim` seconds and the time associated with the last key of the animation is `t_last_key` seconds, then `t_last_key` is less than `t_anim`. So you would need to interpolate from the last key to the first key during a time `t_anim - t_last_key`.

I answered based on my limited knowledge on how things could work, but I’m in no way an expert in the animation area.

I think an animation is made of keys and a time is associated to each key. If the animations last 10s and the last key defined for this animation has an associated time of 9.5s, then you would interpolate between the last key and the first key (assuming the first key has an associated time of 0s…) for 0.5s.

But maybe it does not work that way and I’m off in the explanations.

I think I can now get time by the delta equals length / frame count

But I think I might be messing up because it is root motion… sine the first position is behind the last position … can’t just interpolate from last to first… you end up popping back to beginning of animation

I am probably oversimplifying and showing I don’t really understand but here goes anyway.

My thoughts are that given a consistent motion for a loop the model is in a given state S at the start of frame 1 and at the end of the last frame the model is again at state S but with some displacement d. So there is not a last frame to first frame interpolation to do. At the end of the loop you are back to doing the frame one action. Sorry if I am totally missing the point.