extra info : The “franticness” of the mob also affects this, which means villagers (probably the most frantic) will do this less often, because they go frantic and pick a random direction to run in a lot more when panicking.
Btw it only happens with some cases of flowing water
extra info : This also applies to the ender dragon if you can hit it in fast enough succession lol