how to make AI switch attack because of the distance