put projectile movement updates into fixedupdate
This commit is contained in:
@@ -30,7 +30,11 @@ pub fn plugin(app: &mut App) {
|
||||
app.add_systems(OnEnter(GameState::Playing), setup);
|
||||
app.add_systems(
|
||||
Update,
|
||||
(update, shot_collision, timeout, enemy_hit).run_if(in_state(GameState::Playing)),
|
||||
(shot_collision, enemy_hit).run_if(in_state(GameState::Playing)),
|
||||
);
|
||||
app.add_systems(
|
||||
FixedUpdate,
|
||||
(update, timeout).run_if(in_state(GameState::Playing)),
|
||||
);
|
||||
|
||||
global_observer!(app, on_trigger_gun);
|
||||
@@ -86,10 +90,10 @@ fn on_trigger_gun(
|
||||
|
||||
commands.trigger(PlaySound::Gun);
|
||||
|
||||
let rotation = if let Some(target) = state.target {
|
||||
let t = query_transform
|
||||
.get(target)
|
||||
.expect("target must have transform");
|
||||
let rotation = if let Some(t) = state
|
||||
.target
|
||||
.and_then(|target| query_transform.get(target).ok())
|
||||
{
|
||||
Transform::from_translation(state.pos)
|
||||
.looking_at(t.translation, Vec3::Y)
|
||||
.rotation
|
||||
|
||||
@@ -38,9 +38,10 @@ struct ShotAssets {
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.add_systems(OnEnter(GameState::Playing), setup);
|
||||
app.add_systems(Update, shot_collision.run_if(in_state(GameState::Playing)));
|
||||
app.add_systems(
|
||||
Update,
|
||||
(shot_collision, update, timeout).run_if(in_state(GameState::Playing)),
|
||||
FixedUpdate,
|
||||
(update, timeout).run_if(in_state(GameState::Playing)),
|
||||
);
|
||||
|
||||
global_observer!(app, on_trigger_missile);
|
||||
|
||||
@@ -56,10 +56,9 @@ fn wait_for_player(
|
||||
for agent in agents.iter() {
|
||||
if let Some(player) = in_range(50., agent, &players, &transform) {
|
||||
info!("[{agent}] Engage: {player}");
|
||||
commands
|
||||
.entity(agent)
|
||||
.remove::<WaitForAnyPlayer>()
|
||||
.insert(Engage(player));
|
||||
if let Some(mut agent) = commands.get_entity(agent) {
|
||||
agent.remove::<WaitForAnyPlayer>().insert(Engage(player));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user