put projectile movement updates into fixedupdate

This commit is contained in:
2025-04-28 23:03:25 +02:00
parent c9f17e4130
commit b4bfa53df4
3 changed files with 15 additions and 11 deletions

View File

@@ -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

View File

@@ -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);