Skip to content

Commit

Permalink
enemies choose between multiple players when targeting
Browse files Browse the repository at this point in the history
  • Loading branch information
odecay committed Jul 11, 2022
1 parent 9629e92 commit c36ceca
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use bevy_rapier2d::prelude::*;
use input::MenuAction;
use iyes_loopless::prelude::*;
use leafwing_input_manager::prelude::*;
use rand::Rng;
use rand::{seq::SliceRandom, Rng};
use structopt::StructOpt;

#[cfg(feature = "debug")]
Expand Down Expand Up @@ -610,12 +610,12 @@ fn set_target_near_player(
query: Query<(Entity, &State), (With<Enemy>, Without<Target>)>,
player_query: Query<&Transform, With<Player>>,
) {
//right now this picks only whichever player shows up last, it should collect them and pick a different player for each enemy to target
for player_transform in player_query.iter() {
let mut rng = rand::thread_rng();
let mut rng = rand::thread_rng();
let transforms = player_query.iter().collect::<Vec<_>>();

for (entity, state) in query.iter() {
if *state == State::Idle {
for (entity, state) in query.iter() {
if *state == State::Idle {
if let Some(player_transform) = transforms.choose(&mut rng) {
let x_offset = rng.gen_range(-100.0..100.);
let y_offset = rng.gen_range(-100.0..100.);
commands.entity(entity).insert(Target {
Expand Down

0 comments on commit c36ceca

Please sign in to comment.