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:
@@ -10,7 +10,7 @@ const PLAYERBOID_COLOR: Color = Color::srgb(1.0, 0.0, 0.0);
|
|||||||
const TURN_FACTOR: f32 = 1.;
|
const TURN_FACTOR: f32 = 1.;
|
||||||
const BOID_VIEW_RANGE: f32 = 50.0;
|
const BOID_VIEW_RANGE: f32 = 50.0;
|
||||||
const COHESION_FACTOR: f32 = 0.1;
|
const COHESION_FACTOR: f32 = 0.1;
|
||||||
const SEPARATION_FACTOR: f32 = 10.;
|
const SEPARATION_FACTOR: f32 = 0.05;
|
||||||
|
|
||||||
pub struct BoidsPlugin;
|
pub struct BoidsPlugin;
|
||||||
|
|
||||||
@@ -215,7 +215,7 @@ fn separation(
|
|||||||
// TODO: Make this an exponential so force gets stronger faster as the points approach.
|
// TODO: Make this an exponential so force gets stronger faster as the points approach.
|
||||||
fn separation_force(us: Vec2, neighbor: Vec2) -> Acceleration {
|
fn separation_force(us: Vec2, neighbor: Vec2) -> Acceleration {
|
||||||
let distance = neighbor - us;
|
let distance = neighbor - us;
|
||||||
Acceleration((distance * SEPARATION_FACTOR).extend(0.0))
|
Acceleration(-(distance * SEPARATION_FACTOR).extend(0.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alignment(
|
fn alignment(
|
||||||
|
|||||||
Reference in New Issue
Block a user