You need a dead zone on your Animation transitions make them > 0.1f NOT > 0f you are getting jitter. Hold focus on the character in the object inspector and watch the animator editor transitions.
This is the patch to your code but this is not the proper fix which I will explain next
if (movementDirection.x < 0.1f) {
anim.SetFloat("LastMoveX" , -1f);
} else if (movementDirection.x > 0.1f) {
anim.SetFloat("LastMoveX" , 1f);
} else {
anim.SetFloat("LastMoveX" , 0f);
}
if (movementDirection.y < 0.1f) {
anim.SetFloat("LastMoveY" , -1f);
} else if (movementDirection.y > 0.1f) {
anim.SetFloat("LastMoveY" , 1f);
} else {
anim.SetFloat("LastMoveYX" , 0f);
}
You can do what this code is doing properly just sending it out to the animator control untouched
anim.SetFloat("LastMoveX" , movement.x);
anim.SetFloat("LastMoveY" , movement.y);
Now on the transitions (the "Arrows" between the states) in the animator control change to things like >0.1f and <-0.1f
There is no need to restrict yourself to 0-1 the value passed out to the animator is a float and it can be negative. Basically you have code doing what is much better and simpler to do out at the animator.
So out at the animator editor on those arrows between states change them
Idle state transitions
LastMoveX < -0.1f transition to walking left
LastMoveX > 0.1f transition to walking right
Walk left state transition dropback to idle
LastMoveX > -0.1f transition to idle
Walk right state transition dropback to idle
LastMoveX < 0.1f transition to idle
Organize that on the animator like you are supposed to and your code becomes totally redundant and is not needed.