Is it possible to trigger an animation?

Preface: I am NOT using this for a game so if there is a better way to do this in blender please let me know!

I have 2 animations setup: anim a (idle) and anim b (attack), and I would like to have my character (or multiple if possible) to be doing anim a, and then switch to animation b when a “trigger” happens. This would preferably be either based on the current frame (like switch to anim b on frame 31) ((and if possible I would like to make that random)) OR an object going over the character, as seen in this video:


This video is a great example of what I would like to happen, but if there is a lot of python coding involved I might not be able to do it as I do not know python.

Any help is appreciated, Thanks!