I’m working on a turn-based combat system and my combat system is complete. Now I’m working on implementing the animations. The part I’m stumped on is moving the models back and forth from their starting position to the position where they attack each other. The following code should move the player model up to the enemy and then back away from the enemy. The problem is that it goes up to the enemy model, and then just stays there. It won’t go back. Help?
if(Vector3.Distance(enemy.position, player.position) > 1){
player.position += player.forward * moveSpeed * Time.deltaTime;
if(Vector3.Distance(enemy.position, player.position) < 1){
if(Vector3.Distance(enemy.position, player.position) < 10){
player.position += -player.forward * moveSpeed * Time.deltaTime;
}
}
}