alignment again

main
Zynh Ludwig 2024-09-03 18:52:08 -07:00
parent 56cfd97d77
commit 342597e086
1 changed files with 19 additions and 12 deletions

View File

@ -91,22 +91,29 @@ fn seperation(
fn cohesion(mut boids: Query<(&Transform, &LocalCache, &mut CohesionAcceleration), With<Boid>>) {}
fn alignment(
mut boids: Query<(&LocalCache, &mut AlignmentAcceleration), With<Boid>>,
mut boids: Query<(&Velocity, &LocalCache, &mut AlignmentAcceleration), With<Boid>>,
other_boids: Query<&Velocity, With<Boid>>,
) {
boids.par_iter_mut().for_each(|(local, mut accel)| {
accel.0 = Vec2::ZERO;
let mut count = 0;
for velocity in other_boids.iter_many(&local.0[..]) {
accel.0 += velocity.0;
const MAX_FORCE: f32 = 50.;
count += 1;
}
boids
.par_iter_mut()
.for_each(|(velocity, local, mut accel)| {
accel.0 = Vec2::ZERO;
let mut count = 0;
for other_velocity in other_boids.iter_many(&local.0[..]) {
accel.0 += other_velocity.0;
if count > 0 {
accel.0 /= count as f32;
}
});
count += 1;
}
if count > 0 {
accel.0 /= count as f32;
accel.0 -= velocity.0;
accel.0 = accel.0.clamp_length_max(MAX_FORCE);
}
});
}
fn accelerate(