Skip to content

Commit

Permalink
feat: make enemies run away from the player if they are closer than t…
Browse files Browse the repository at this point in the history
…he ideal distance
  • Loading branch information
umut-sahin committed Jan 22, 2024
1 parent bb1ba16 commit e68f6c3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions game/src/enemy/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ pub fn follow_player<E: IEnemy + Component>(
{
let ideal_distance = *ideal_distance.cloned().unwrap_or(IdealDistanceToPlayer(25.00));
let direction = player_position.0 - enemy_position.0;
enemy_velocity.0 = if direction.length() > ideal_distance {
direction.normalize() * enemy_speed.0
} else {
Vec2::ZERO
};

enemy_velocity.0 = direction.normalize() * enemy_speed.0;
if direction.length() < ideal_distance {
enemy_velocity.0 /= -2.00;
}
}
}
}

0 comments on commit e68f6c3

Please sign in to comment.