From 13cacb558e500637ed5bbdb64a6ec2f383bfb1f6 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Wed, 10 Jul 2024 10:53:12 -0500 Subject: [PATCH] Fix: force direction & magnitude for separation The clumping was because the function was moving the boids together, not apart. The chaotic movement was the result of the large coefficient on the force. --- src/birdoids_plugin.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/birdoids_plugin.rs b/src/birdoids_plugin.rs index bb2e18af..61fdefb0 100644 --- a/src/birdoids_plugin.rs +++ b/src/birdoids_plugin.rs @@ -10,7 +10,7 @@ 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.; +const SEPARATION_FACTOR: f32 = 0.05; pub struct BoidsPlugin; @@ -215,7 +215,7 @@ fn separation( // TODO: Make this an exponential so force gets stronger faster as the points approach. fn separation_force(us: Vec2, neighbor: Vec2) -> Acceleration { let distance = neighbor - us; - Acceleration((distance * SEPARATION_FACTOR).extend(0.0)) + Acceleration(-(distance * SEPARATION_FACTOR).extend(0.0)) } fn alignment(