What I find confusing about your code is that it happens all in a while loop; I would move some of it to a new function and call that instead (with an if() before it ofcourse) to make the code cleaner and to see the bugs faster.

Also this action is named wizardEnemy_action yet you describe it is about the player, is wizardEnemy_action a spelling/c&p mistake or does the player get moved by the enemy? (if so, than that sounds confusing too)