last tinkering

main
Zynh Ludwig 2024-09-07 05:23:53 -07:00
parent 6ca933a1b1
commit 2ead92970e
1 changed files with 32 additions and 11 deletions

View File

@ -24,8 +24,8 @@ fn main() {
Update,
(
build_local_cache,
(seperation_gizmos),
// (seperation, cohesion, alignment),
// (seperation_gizmos),
(seperation, cohesion, alignment),
accelerate,
move_boids,
boundary::boid_border_teleport,
@ -93,8 +93,10 @@ fn cohesion(
count += 1;
}
accel.0 /= count as f32;
accel.0 -= transform.translation.xy();
if count > 0 {
accel.0 /= count as f32;
accel.0 -= transform.translation.xy();
}
})
}
@ -108,11 +110,9 @@ fn seperation_gizmos(
.iter_many(&local.0)
.take(1)
.for_each(|other_transform| {
let distance = transform.translation.distance(other_transform.translation);
let diff_scale = (distance / VISION_RANGE);
// let distance = transform.translation.distance(other_transform.translation);
let mut diff = transform.translation - other_transform.translation;
diff *= diff_scale;
let diff = transform.translation - other_transform.translation;
gizmos.arrow(
transform.translation,
@ -133,6 +133,27 @@ fn seperation(
mut boids: Query<(&Transform, &LocalCache, &mut SeperationAcceleration), With<Boid>>,
other_boids: Query<&Transform, With<Boid>>,
) {
const MAX_FORCE: f32 = 100.;
boids
.par_iter_mut()
.for_each(|(transform, local, mut accel)| {
accel.0 = Vec2::ZERO;
let mut count = 0;
other_boids
.iter_many(&local.0)
.take(1)
.for_each(|other_transform| {
let diff = transform.translation - other_transform.translation;
let diff = diff.normalize();
accel.0 += diff.xy();
count += 1;
});
accel.0 *= 150.;
// accel.0 = accel.0.clamp_length_max(MAX_FORCE);
});
}
fn alignment(
@ -205,9 +226,9 @@ fn setup(
mut time: ResMut<Time<Virtual>>,
mut config_store: ResMut<GizmoConfigStore>,
) {
time.set_relative_speed(0.1);
// time.set_relative_speed(1.);
let (gizmo_config, _) = config_store.config_mut::<DefaultGizmoConfigGroup>();
gizmo_config.line_width = 5.;
gizmo_config.line_width = 2.5;
let window = windows.get_single().unwrap();
let half_width = window.resolution.width() / 4.;
@ -221,7 +242,7 @@ fn setup(
let lower_height = -half_height;
let upper_height = half_height;
for i in 0..500 {
for i in 0..250 {
use std::f32::consts::TAU;
let x = small_rng.gen_range(lower_width..=upper_width);