Need help giving my GeckoLib model Armadillo like hiding

I've created a creature and Built-In animations work amazingly but I can't seem to find a way for my entity to play another animation named "hiding" when the playing is within 8 blocks.
I also want it to end once the entity is attacked so it goes aggressive

If anyone knows the solution to this that would be so appriciated.