From bb33fda01859df4c401f03f91262074de8886052 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Thu, 11 Jul 2024 16:53:38 -0500 Subject: [PATCH] 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. --- src/birdoids_plugin.rs | 8 ++++---- src/debug_plugin.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/birdoids_plugin.rs b/src/birdoids_plugin.rs index 1d4ddcec..d0faa7a5 100644 --- a/src/birdoids_plugin.rs +++ b/src/birdoids_plugin.rs @@ -19,7 +19,7 @@ impl Plugin for BoidsPlugin { fn build(&self, app: &mut App) { app .add_plugins(AutomaticUpdate::::new() - .with_frequency(Duration::from_secs_f32(0.3)) + // .with_frequency(Duration::from_secs_f32(0.3)) .with_transform(TransformMode::GlobalTransform) .with_spatial_ds(SpatialStructure::KDTree2)) .insert_resource(ClearColor(BACKGROUND_COLOR)) @@ -28,10 +28,10 @@ impl Plugin for BoidsPlugin { apply_velocity, turn_if_edge, check_keyboard, - // cohesion, + cohesion, separation, - // alignment, - space_brakes, + alignment, + // space_brakes, )); } } diff --git a/src/debug_plugin.rs b/src/debug_plugin.rs index f7692c24..18713342 100644 --- a/src/debug_plugin.rs +++ b/src/debug_plugin.rs @@ -159,7 +159,7 @@ fn do_scan( boids.iter().map(|item| { 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!")); - (*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()