diff --git a/src/birdoids_plugin.rs b/src/birdoids_plugin.rs index 7064da41..bb2e18af 100644 --- a/src/birdoids_plugin.rs +++ b/src/birdoids_plugin.rs @@ -10,6 +10,8 @@ const PLAYERBOID_COLOR: Color = Color::srgb(1.0, 0.0, 0.0); const TURN_FACTOR: f32 = 1.; const BOID_VIEW_RANGE: f32 = 50.0; const COHESION_FACTOR: f32 = 0.1; +const SEPARATION_FACTOR: f32 = 10.; + pub struct BoidsPlugin; impl Plugin for BoidsPlugin { @@ -25,7 +27,8 @@ impl Plugin for BoidsPlugin { apply_velocity, turn_if_edge, check_keyboard, - cohesion, + // cohesion, + separation, )); } } @@ -41,6 +44,9 @@ struct PlayerBoid; #[derive(Component, Deref, DerefMut)] struct Velocity(Vec3); +#[derive(Component, Deref, DerefMut)] +struct Acceleration(Vec3); + #[derive(Component)] struct TrackedByKdTree; @@ -48,6 +54,7 @@ struct TrackedByKdTree; struct BoidBundle { boid: Boid, velocity: Velocity, + accel: Acceleration, spatial: TrackedByKdTree, } @@ -56,6 +63,7 @@ impl BoidBundle { Self { boid: Boid, velocity: Velocity(vel), + accel: Acceleration(Vec3::ZERO), spatial: TrackedByKdTree, } } @@ -120,9 +128,13 @@ fn turn_if_edge( } } -fn apply_velocity(mut query: Query<(&mut Transform, &Velocity)>, time: Res