Game Loops & Timing
Fixed vs variable timestep in Bevy - stable physics, smooth rendering, and frame-rate independence.
Busca en todas las páginas de la documentación
Fixed vs variable timestep in Bevy - stable physics, smooth rendering, and frame-rate independence.
fn physics_step(mut q: Query<&mut Position>, time: Res<Time<Fixed>>) {
let dt = time.delta_secs();
for mut pos in &mut q {
pos.0 += dt * 10.0;
}
}
// App::new().add_systems(FixedUpdate, physics_step);When to reach for this:
use bevy::prelude::*;
#[derive(Component)]
struct SimPosition(f32);
#[derive(Component)]
struct RenderPosition(f32);
fn fixed_sim(mut q: Query<&mut SimPosition>, time: Res<Time<Fixed>>) {
for mut sim in &mut q {
sim.0 += 100.0 * time.delta_secs();
}
}
fn interpolate_render(
sim_q: Query<&SimPosition>,
mut render_q: Query<&mut RenderPosition>,
time: Res<Time<Fixed>>,
) {
let alpha = time.overstep_fraction();
for (sim, mut render) in sim_q.iter().zip(render_q.iter_mut()) {
// Simplified: in full engine store previous sim for true lerp
render.0 = sim.0;
let _ = alpha;
}
}What this demonstrates:
FixedUpdateoverstep_fraction hook for interpolation alphadelta_secs.| Schedule | Typical systems |
|---|---|
FixedUpdate | Physics, deterministic sim |
Update | Input, animation state machines |
PostUpdate | Camera follow interpolated transform |
Update with delta_secs - unstable stacks. Fix: move to FixedUpdate only.Update with variable time.Fixed Hz.| Alternative | Use When | Don't Use When |
|---|---|---|
| Variable everything | Simple non-physics arcade | Stacks, ragdolls, competitive physics |
| Fixed 30 Hz sim | Mobile budget | PC high refresh competitive |
| Deterministic lockstep net | RTS peer-to-peer | Single-player only |
| Manual accumulator custom engine | Non-Bevy | Already on Bevy schedules |
60 Hz common default; 30 Hz on mobile saves CPU; fighting games may need 60+ with rollback netcode.
Time variable, Time<Fixed> for fixed schedule, Time<Virtual> for pause/slow-mo.
Pause Time<Virtual> or disable schedules while menu open - UI still animates if desired.
Scale virtual time factor affecting Update; decide if physics should also slow.
Clamp huge delta_secs after loading hitch to avoid teleport - common pattern max 0.25s.
Tracy spans per schedule; compare FixedUpdate ms vs render ms.
Poll input once per rendered frame; apply in fixed step via buffered intents.
Timeline driven by fixed or real time depending on sync to physics needs.
TimePlugin sets fixed timestep in App - consult version docs for FixedTime resource API.
Game Dev Basics Time resource example.
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Revisado por Chris St. John·Última actualización: 16 jul 2026