How to calculate direction the animation "Jogging to standing" ?

My animation system is based on animation like fortnite. When the “S” button is pressed, the character does the animation of walking backwards, and the same for right, left and forward. I used “calculate direction”. But when I release the move button, the standing animation is always forward. How to calculate the direction of the last movement?

These are my codes:



Video of how the character stop: