To keep the enemy character from getting too close to your player, you need to add a bit of code that checks how close the enemy is to the player. If the enemy gets too close, closer than a distance you decide is just right, the code should make the enemy either stop or back away.