How to switch animations?

I am making a data pack with a friend and we have made a monster with animated java and i have made an animation for idle and chasing how should i detect movement and then change the animation accordingly? I also have an attck animation, how should i detect that? It is in 1.21.2 btw

Continue to help post