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.
This commit is contained in:
2024-07-10 10:53:12 -05:00
parent 368d6c9201
commit 13cacb558e

View File

@@ -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(