Character weird rotate while jumping

So when I jump with my character while walking or running character is rotating something like it losing his direction and when jump it turns left or right and when it land is ok again. Same thing was happening when character jump from idle but I solved this problem by setting up direction to 0 while velocity on X and Y axis is 0 but I have no idea how tto fix this with walking and running

Ok I solved it. Simply I broke velocity vector and make vector without Z axis and plugged it to calculate direction node

Thank you, I was having a similar issue and your solution fixed it!