Fix: spatial tree update frequency is too low

The reubild frequency of the spatial tree was causing calculations to
operate on old information. This is not the intended behavior. The
default schedule seems to be to run every frame.

I also lowered the debug pointer coefficient. Boids moving at a normal
velocity are actually fast enough to draw a meaningful line. Maybe I'll
switch it into some kind of exponential space so small changes are
visible, and big changes don't draw a line all the way across the
screen.
This commit is contained in:
2024-07-11 16:53:38 -05:00
parent 8001bbceb9
commit bb33fda018
2 changed files with 5 additions and 5 deletions

View File

@@ -19,7 +19,7 @@ impl Plugin for BoidsPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app app
.add_plugins(AutomaticUpdate::<TrackedByKdTree>::new() .add_plugins(AutomaticUpdate::<TrackedByKdTree>::new()
.with_frequency(Duration::from_secs_f32(0.3)) // .with_frequency(Duration::from_secs_f32(0.3))
.with_transform(TransformMode::GlobalTransform) .with_transform(TransformMode::GlobalTransform)
.with_spatial_ds(SpatialStructure::KDTree2)) .with_spatial_ds(SpatialStructure::KDTree2))
.insert_resource(ClearColor(BACKGROUND_COLOR)) .insert_resource(ClearColor(BACKGROUND_COLOR))
@@ -28,10 +28,10 @@ impl Plugin for BoidsPlugin {
apply_velocity, apply_velocity,
turn_if_edge, turn_if_edge,
check_keyboard, check_keyboard,
// cohesion, cohesion,
separation, separation,
// alignment, alignment,
space_brakes, // space_brakes,
)); ));
} }
} }

View File

@@ -159,7 +159,7 @@ fn do_scan(
boids.iter().map(|item| { boids.iter().map(|item| {
let entity_id = item.1.unwrap_or_else(|| panic!("Entity has no ID!")); let entity_id = item.1.unwrap_or_else(|| panic!("Entity has no ID!"));
let (_, vel, _) = boids_query.get(entity_id).unwrap_or_else(|_| panic!("Boid has no Velocity component!")); let (_, vel, _) = boids_query.get(entity_id).unwrap_or_else(|_| panic!("Boid has no Velocity component!"));
(*vel).xy() * 50.0 (*vel).xy() * 1.0
}) })
) { ) {
// cursor_pos.translation is already in world space, so I can skip the window -> world transform like in update_cursor() // cursor_pos.translation is already in world space, so I can skip the window -> world transform like in update_cursor()