Animation problems in 2D movement State machine implementation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lodestar

I currently have a state machine that switches between idle and move states for the player.

For the move state when keyboard input is not detected it will switch to the idle state, this is all done by physics processing.

While the player is moving in the move state by holding down the right key, letting go of the right key and swapping to the left key will cause a switch to the idle state and play the idle animation for a split second even if done in quick succession. This is unwanted because it interrupts “smooth” movement animation when moving in opposite directions. Moving clockwise/counter-clockwise does not cause a shift because my code still detects a non zero input direction vector.

I want to add some sort of delay to give the player a small window of time to enter the new direction and keep a persistent move state and animation