Skip to content

Commit

Permalink
examples/ecs/iter_combinations: Initialize velocity using fixed times…
Browse files Browse the repository at this point in the history
…tep (#10673)

# Objective

On some platforms (observed on Windows and Linux, works fine on web),
velocity of all entities would be initialized to zero, making them
simply fall into the star.

## Solution

Using `Time<Fixed>::timestep` instead of `Time::delta_seconds` to
initialize velocity. Since the entities are generated in the startup
schedule, no time has elapsed yet and `Time::delta_seconds` would return
zero on some platforms. `Time<Fixed>::timestep` will always return the
expected time step of `FixedUpdate` schedule.
  • Loading branch information
IWonderWhatThisAPIDoes authored Feb 27, 2024
1 parent fd0f1a3 commit 8020805
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/ecs/iter_combinations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct BodyBundle {
}

fn generate_bodies(
time: Res<Time>,
time: Res<Time<Fixed>>,
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
Expand Down Expand Up @@ -81,7 +81,7 @@ fn generate_bodies(
rng.gen_range(vel_range.clone()),
rng.gen_range(vel_range.clone()),
rng.gen_range(vel_range.clone()),
) * time.delta_seconds(),
) * time.timestep().as_secs_f32(),
),
});
}
Expand Down

0 comments on commit 8020805

Please sign in to comment.