this system would work of you were to move straight up and down, but im not too sure about diagonal. you could, however, force the player to move diagonally toward the NPC (up-right), use the east melee, (which would attack to the upper right direction) then have to go back diagonally(down-left).