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 onTime<Virtual>
. The fixed clock is automatically set as the generic [Time
] resource duringFixedUpdate
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 commonlyFixedUpdate
.This schedule is run a number of times between
PreUpdate
andUpdate
according to the accumulatedoverstep()
time divided by thetimestep()
. 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 adelta()
equal totimestep()
and always growelapsed()
by onetimestep()
per iteration.The fixed timestep clock follows the
Time<Virtual>
clock, which means it is affected bypause()
,set_relative_speed()
andset_max_delta()
from virtual time. If the virtual clock is paused, theFixedUpdate
schedule will not run. It is guaranteed that theelapsed()
time inTime<Fixed>
is always between the previouselapsed()
and the currentelapsed()
value inTime<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 theFixedUpdate
schedule, meaning that it will affect thedelta()
value for the very nextFixedUpdate
, even if it is still during the same frame. Anyoverstep()
present in the accumulator will be processed according to the newtimestep()
value.
Functions
Function | Summary |
---|---|
clone(_self) | No Documentation 🚧 |