From 7a97abdeb116a7ba5039dab649eb504476cde69e Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Sun, 3 Dec 2023 12:49:30 -0800 Subject: [PATCH] update camera to follow center of flock --- .rustfmt.toml | 4 +++ assets/models/toid.glb | Bin 0 -> 1760 bytes src/lib.rs | 72 +++++++++++++++++++++++++++++++++++------ src/main.rs | 46 ++------------------------ src/systems.rs | 0 5 files changed, 70 insertions(+), 52 deletions(-) create mode 100644 .rustfmt.toml create mode 100644 assets/models/toid.glb delete mode 100644 src/systems.rs diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..4c8d0e1 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,4 @@ +imports_granularity = "Crate" +group_imports = "StdExternalCrate" +wrap_comments = true +edition = "2021" diff --git a/assets/models/toid.glb b/assets/models/toid.glb new file mode 100644 index 0000000000000000000000000000000000000000..e879db6105980c612b4551eef394bbea7be48803 GIT binary patch literal 1760 zcmb7FPlyv&7=OC{x2-2Hp29GSg|^uqy(mbb&_kg;cO?fM9dVfpe2_hjKG}oM;?a=bT#( zaX4etkveI$Y|d z@{gW=-rr2ti#Ye=GcEsh`(l1G`OCHEg?%^wP&k{(E7Jp<{~jFaZzi9v-2b(A=-BGR z>KCWCBLDT-TK?vQQ5c<9rf(GF9iiL#@-LsJ&dGwjPm1uAw2#iOexF$P$9E4Z|G_y~ z7~K(?RQfla|B$==14j?{>)*wN``)f3wPCo3;*6-qz+#L_+=PTa|V zvv#z92>jDNe?R{7x2O4)eg$H;;GzIUQM=p`{nOXUCn literal 0 HcmV?d00001 diff --git a/src/lib.rs b/src/lib.rs index ce122b1..dd7d699 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,15 +8,15 @@ use bevy_spatial::{kdtree::KDTree3, SpatialAccess}; pub type NNTree = KDTree3; // toid stuff -const SPEED: f32 = 5.0; +const SPEED: f32 = 2.0; const SPEED_DIFF_RANGE: f32 = 0.1; // +/- 10% const MAX_DELTA_V: f32 = std::f32::consts::PI * 2.0; // basically 360 degrees/sec // how far from origin before really wanting to come back -const RADIUS: f32 = 50.0; +const RADIUS: f32 = 40.0; // how close to try to stay to your buddies -const BUDDY_RADIUS: f32 = 30.0; +const BUDDY_RADIUS: f32 = 10.0; const MIN_ALTITUDE: f32 = 3.5; @@ -43,6 +43,9 @@ pub struct Toid { pub buddies: usize, } +#[derive(Debug, Default, Clone, Copy, Deref, DerefMut, Resource)] +pub struct LookAt(Vec3); + pub fn turkey_time( commands: &mut Commands, scene: &Handle, @@ -67,10 +70,11 @@ pub fn turkey_time( scene: scene.to_owned(), ..Default::default() }) - .insert(Transform::from_rotation(Quat::from_axis_angle( - Vec3::Y, - -std::f32::consts::FRAC_PI_2, - ))); + .insert(Transform::default()); + // .insert(Transform::from_rotation(Quat::from_axis_angle( + // Vec3::Y, + // -std::f32::consts::FRAC_PI_2, + // ))); }) .id() } @@ -101,7 +105,7 @@ pub fn update_vel( } // avoid flying into neighbors - let min_dist = speed / 2.0; + let min_dist = speed; for neighbor in index .within_distance(pos, min_dist) .iter() @@ -151,15 +155,19 @@ pub fn update_vel( pub fn update_pos( mut toids: Query<(&mut Transform, &Velocity, Entity), With>, mut positions: ResMut, + mut lookat: ResMut, time: Res