When you press backward, the “controller direction” will flip flop between -180 and 180, which causes the “animation direction” to flip between walking back right and back left. You can solve this by feeding all “controller direction” values from -170 to 170 into the “animation direction”, but anything outside this range should be converted to just 180 before feeding them into the “animation direction”.