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