Fix cohesion force vector
Found it! The force was going the wrong way.
This commit is contained in:
@@ -172,7 +172,7 @@ fn cohesion(
|
|||||||
.sum::<Vec2>() / neighbors.len() as f32;
|
.sum::<Vec2>() / neighbors.len() as f32;
|
||||||
|
|
||||||
for (transform, mut velocity) in &mut query {
|
for (transform, mut velocity) in &mut query {
|
||||||
let towards = (transform.translation.xy() - center_of_mass).normalize();
|
let towards = (center_of_mass - transform.translation.xy()).normalize();
|
||||||
**velocity += towards.extend(0.0) * COHESION_FACTOR;
|
**velocity += towards.extend(0.0) * COHESION_FACTOR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user