Fixed

Fixed

  • timestep : bevy_utils::Duration
  • overstep : bevy_utils::Duration

Description

The fixed timestep game clock following virtual time.

A specialization of the [Time] structure. For method documentation, see [Time<Fixed>#impl-Time<Fixed>].

It is automatically inserted as a resource by TimePlugin and updated based on Time<Virtual>. The fixed clock is automatically set as the generic [Time] resource during FixedUpdate schedule processing.

The fixed timestep clock advances in fixed-size increments, which is extremely useful for writing logic (like physics) that should have consistent behavior, regardless of framerate.

The default timestep() is 64 hertz, or 15625 microseconds. This value was chosen because using 60 hertz has the potential for a pathological interaction with the monitor refresh rate where the game alternates between running two fixed timesteps and zero fixed timesteps per frame (for example when running two fixed timesteps takes longer than a frame). Additionally, the value is a power of two which losslessly converts into [f32] and [f64].

To run a system on a fixed timestep, add it to one of the [FixedMain] schedules, most commonly FixedUpdate.

This schedule is run a number of times between PreUpdate and Update according to the accumulated overstep() time divided by the timestep(). This means the schedule may run 0, 1 or more times during a single update (which typically corresponds to a rendered frame).

Time<Fixed> and the generic [Time] resource will report a delta() equal to timestep() and always grow elapsed() by one timestep() per iteration.

The fixed timestep clock follows the Time<Virtual> clock, which means it is affected by pause(), set_relative_speed() and set_max_delta() from virtual time. If the virtual clock is paused, the FixedUpdate schedule will not run. It is guaranteed that the elapsed() time in Time<Fixed> is always between the previous elapsed() and the current elapsed() value in Time<Virtual>, so the values are compatible.

Changing the timestep size while the game is running should not normally be done, as having a regular interval is the point of this schedule, but it may be necessary for effects like "bullet-time" if the normal granularity of the fixed timestep is too big for the slowed down time. In this case, set_timestep() and be called to set a new value. The new value will be used immediately for the next run of the FixedUpdate schedule, meaning that it will affect the delta() value for the very next FixedUpdate, even if it is still during the same frame. Any overstep() present in the accumulator will be processed according to the new timestep() value.

Functions

FunctionSummary
clone(_self)No Documentation 🚧