Using direction/angle to change animation?

This is for a 2D infinte runner - I asked a previous question, but thought about it some more and have come up with a fairly vague answer that I’m not too sure about. I have a player (see diagram) that when he jumps he might miss the obstacle and play his animation regardless (which is what I don’t want).

So what I was thinking - what if I had a raycast pointing toward his nearest obstacle, retrieving that angle (or mathematical function), and if it’s within a threshold of whatever angle I set it will play a specific animation. This way it might not play the animation if he will miss the obstacle. Is something like this possible? Or is there something easier?

Some additional info - player’s x and z values are frozen (he only jumps). Obstacles constantly fly at him.

Check collision for your obstacle, if it is collided then play your specific animation, also you can put your obstacle inside an invisible box collider , then you can define boundary for your collision and check the collision in that boundary.