checkpoint
This commit is contained in:
parent
7a97abdeb1
commit
5bb6d10558
2 changed files with 17 additions and 14 deletions
29
src/lib.rs
29
src/lib.rs
|
@ -8,12 +8,12 @@ use bevy_spatial::{kdtree::KDTree3, SpatialAccess};
|
|||
pub type NNTree = KDTree3<Toid>;
|
||||
|
||||
// toid stuff
|
||||
const SPEED: f32 = 2.0;
|
||||
const SPEED: f32 = 0.2;
|
||||
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 = 40.0;
|
||||
const RADIUS: f32 = 50.0;
|
||||
|
||||
// how close to try to stay to your buddies
|
||||
const BUDDY_RADIUS: f32 = 10.0;
|
||||
|
@ -58,8 +58,9 @@ pub fn turkey_time(
|
|||
let x = r.gen_range(-10.0..=10.0);
|
||||
let z = r.gen_range(-10.0..=10.0);
|
||||
let y = r.gen_range(0.1..=5.5);
|
||||
let pos = Vec3::new(x, MIN_ALTITUDE + y, z);
|
||||
let spatial_bundle = SpatialBundle {
|
||||
transform: Transform::from_xyz(x, MIN_ALTITUDE + y, z),
|
||||
transform: Transform::from_translation(pos),
|
||||
..Default::default()
|
||||
};
|
||||
commands
|
||||
|
@ -70,11 +71,11 @@ pub fn turkey_time(
|
|||
scene: scene.to_owned(),
|
||||
..Default::default()
|
||||
})
|
||||
.insert(Transform::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()
|
||||
}
|
||||
|
@ -94,7 +95,7 @@ pub fn update_vel(
|
|||
let original_dir = dir;
|
||||
|
||||
// find buddies and orient; point more towards further-away buddies
|
||||
for buddy in buddies.0.iter() {
|
||||
for buddy in buddies.iter() {
|
||||
let bp = positions.get(buddy).unwrap();
|
||||
let bdir = *bp - pos;
|
||||
let dist = bdir.length();
|
||||
|
@ -105,7 +106,7 @@ pub fn update_vel(
|
|||
}
|
||||
|
||||
// avoid flying into neighbors
|
||||
let min_dist = speed;
|
||||
let min_dist = speed * 10.0;
|
||||
for neighbor in index
|
||||
.within_distance(pos, min_dist)
|
||||
.iter()
|
||||
|
@ -161,9 +162,11 @@ pub fn update_pos(
|
|||
let mut new_look = Vec3::ZERO;
|
||||
let dt = time.delta_seconds();
|
||||
for (mut xform, vel, entity) in toids.iter_mut() {
|
||||
let look_at = xform.translation + vel.0;
|
||||
xform.translation += vel.0 * dt;
|
||||
xform.look_at(look_at, Vec3::Y);
|
||||
xform.translation += **vel * dt;
|
||||
let look_at = xform.translation + **vel;
|
||||
let right = look_at.cross(Vec3::Y).normalize();
|
||||
let up = right.cross(look_at).normalize();
|
||||
xform.look_at(look_at, up);
|
||||
*positions.entry(entity).or_insert(Vec3::ZERO) = xform.translation;
|
||||
new_look += xform.translation;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ fn main() {
|
|||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, (update_pos, update_buddies, update_vel).chain())
|
||||
.add_systems(Update, (rotate_camera, bevy::window::close_on_esc))
|
||||
//.add_systems(Update, update_gizmos)
|
||||
.add_systems(Update, update_gizmos)
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue