Skip to content

Commit fb30f32

Browse files
committed
fix: enemy agents not moving
1 parent 956ca33 commit fb30f32

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/enemy/ai/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
},
99
shooting::systems::enemy_shoot_player,
1010
},
11-
game_flow::states::AppState,
11+
game_flow::states::InGameState,
1212
};
1313

1414
mod systems;
@@ -38,7 +38,7 @@ impl Plugin for EnemyAiPlugin {
3838
check_if_enemy_reached_target,
3939
set_zero_velocity_if_not_chasing,
4040
)
41-
.run_if(in_state(AppState::InGame)),
41+
.run_if(in_state(InGameState::Playing)),
4242
);
4343
}
4444
}

src/enemy/ai/systems.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ pub fn handle_chasing_enemies(
162162
continue;
163163
}
164164

165+
debug!("Applying agent velocity to actual velocity of enemy");
165166
velocity.0 = agent_velocity.velocity;
166167
}
167168
}

src/enemy/spawn/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
},
99
nav_mesh_pathfinding::{ArchipelagoRef, ENEMY_AGENT_RADIUS},
1010
};
11-
use avian3d::{math::PI, prelude::LinearVelocity};
11+
use avian3d::{math::PI, prelude::*};
1212
use bevy::prelude::*;
1313
use bevy_landmass::{
1414
Agent, Agent3dBundle, AgentSettings, AgentTarget3d, ArchipelagoRef3d,
@@ -137,8 +137,14 @@ fn handle_spawn_enemies_at_enemy_spawn_locations_message(
137137
0.5,
138138
TimerMode::Repeating,
139139
)),
140+
RigidBody::Kinematic,
141+
Collider::capsule(
142+
CHARACTER_CAPSULE_RADIUS,
143+
CHARACTER_CAPSULE_LENGTH,
144+
),
140145
Visibility::Visible,
141146
LinearVelocity::ZERO,
147+
CollidingEntities::default(),
142148
))
143149
.with_child((
144150
Transform {

src/nav_mesh_pathfinding/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,16 @@ fn generate_navmesh_when_map_colliders_ready(
7070
}
7171

7272
fn update_agent_velocity(
73-
mut agent_query: Query<(&mut Velocity3d, &AgentDesiredVelocity3d)>,
73+
mut agent_query: Query<(
74+
&mut Velocity3d,
75+
&AgentDesiredVelocity3d,
76+
&AgentState,
77+
)>,
7478
) {
75-
for (mut velocity, desired_velocity) in agent_query.iter_mut() {
76-
velocity.velocity = desired_velocity.velocity();
79+
for (mut agent_velocity, desired_velocity, agent_state) in
80+
agent_query.iter_mut()
81+
{
82+
debug!("Agent state: {:?}", agent_state);
83+
agent_velocity.velocity = desired_velocity.velocity();
7784
}
7885
}

0 commit comments

Comments
 (0)