seperation
This commit is contained in:
parent
69ddd9c753
commit
b0a1676fd2
1 changed files with 23 additions and 3 deletions
26
src/main.rs
26
src/main.rs
|
@ -83,12 +83,32 @@ fn build_local_cache(
|
|||
});
|
||||
}
|
||||
|
||||
fn seperation(
|
||||
mut boids: Query<(&Transform, &LocalCache, &mut SeperationAcceleration), With<Boid>>,
|
||||
fn cohesion(
|
||||
mut boids: Query<(&Transform, &LocalCache, &mut CohesionAcceleration), With<Boid>>,
|
||||
other_boids: Query<&Transform, With<Boid>>,
|
||||
) {
|
||||
}
|
||||
|
||||
fn cohesion(mut boids: Query<(&Transform, &LocalCache, &mut CohesionAcceleration), With<Boid>>) {}
|
||||
fn seperation(
|
||||
mut boids: Query<(&Transform, &LocalCache, &mut SeperationAcceleration), With<Boid>>,
|
||||
other_boids: Query<&Transform, With<Boid>>,
|
||||
) {
|
||||
boids
|
||||
.par_iter_mut()
|
||||
.for_each(|(transform, local, mut accel)| {
|
||||
accel.0 = Vec2::ZERO;
|
||||
|
||||
let mut count = 0;
|
||||
for transform in other_boids.iter_many(&local.0[..]) {
|
||||
accel.0 += transform.translation.xy();
|
||||
|
||||
count += 1;
|
||||
}
|
||||
|
||||
accel.0 /= count as f32;
|
||||
accel.0 = transform.translation.xy() - accel.0;
|
||||
})
|
||||
}
|
||||
|
||||
fn alignment(
|
||||
mut boids: Query<(&Velocity, &LocalCache, &mut AlignmentAcceleration), With<Boid>>,
|
||||
|
|
Loading…
Reference in a new issue