last tinkering
This commit is contained in:
parent
6ca933a1b1
commit
2ead92970e
1 changed files with 32 additions and 11 deletions
39
src/main.rs
39
src/main.rs
|
@ -24,8 +24,8 @@ fn main() {
|
||||||
Update,
|
Update,
|
||||||
(
|
(
|
||||||
build_local_cache,
|
build_local_cache,
|
||||||
(seperation_gizmos),
|
// (seperation_gizmos),
|
||||||
// (seperation, cohesion, alignment),
|
(seperation, cohesion, alignment),
|
||||||
accelerate,
|
accelerate,
|
||||||
move_boids,
|
move_boids,
|
||||||
boundary::boid_border_teleport,
|
boundary::boid_border_teleport,
|
||||||
|
@ -93,8 +93,10 @@ fn cohesion(
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if count > 0 {
|
||||||
accel.0 /= count as f32;
|
accel.0 /= count as f32;
|
||||||
accel.0 -= transform.translation.xy();
|
accel.0 -= transform.translation.xy();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,11 +110,9 @@ fn seperation_gizmos(
|
||||||
.iter_many(&local.0)
|
.iter_many(&local.0)
|
||||||
.take(1)
|
.take(1)
|
||||||
.for_each(|other_transform| {
|
.for_each(|other_transform| {
|
||||||
let distance = transform.translation.distance(other_transform.translation);
|
// let distance = transform.translation.distance(other_transform.translation);
|
||||||
let diff_scale = (distance / VISION_RANGE);
|
|
||||||
|
|
||||||
let mut diff = transform.translation - other_transform.translation;
|
let diff = transform.translation - other_transform.translation;
|
||||||
diff *= diff_scale;
|
|
||||||
|
|
||||||
gizmos.arrow(
|
gizmos.arrow(
|
||||||
transform.translation,
|
transform.translation,
|
||||||
|
@ -133,6 +133,27 @@ fn seperation(
|
||||||
mut boids: Query<(&Transform, &LocalCache, &mut SeperationAcceleration), With<Boid>>,
|
mut boids: Query<(&Transform, &LocalCache, &mut SeperationAcceleration), With<Boid>>,
|
||||||
other_boids: Query<&Transform, 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(
|
fn alignment(
|
||||||
|
@ -205,9 +226,9 @@ fn setup(
|
||||||
mut time: ResMut<Time<Virtual>>,
|
mut time: ResMut<Time<Virtual>>,
|
||||||
mut config_store: ResMut<GizmoConfigStore>,
|
mut config_store: ResMut<GizmoConfigStore>,
|
||||||
) {
|
) {
|
||||||
time.set_relative_speed(0.1);
|
// time.set_relative_speed(1.);
|
||||||
let (gizmo_config, _) = config_store.config_mut::<DefaultGizmoConfigGroup>();
|
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 window = windows.get_single().unwrap();
|
||||||
let half_width = window.resolution.width() / 4.;
|
let half_width = window.resolution.width() / 4.;
|
||||||
|
@ -221,7 +242,7 @@ fn setup(
|
||||||
let lower_height = -half_height;
|
let lower_height = -half_height;
|
||||||
let upper_height = half_height;
|
let upper_height = half_height;
|
||||||
|
|
||||||
for i in 0..500 {
|
for i in 0..250 {
|
||||||
use std::f32::consts::TAU;
|
use std::f32::consts::TAU;
|
||||||
|
|
||||||
let x = small_rng.gen_range(lower_width..=upper_width);
|
let x = small_rng.gen_range(lower_width..=upper_width);
|
||||||
|
|
Loading…
Reference in a new issue