cohesion scaffold

main
Zynh Ludwig 2024-09-02 21:40:11 -07:00
parent 3cab0eecd5
commit b2b59d68d5
1 changed files with 19 additions and 0 deletions

View File

@ -19,13 +19,32 @@ struct Boid;
#[derive(Component, Default)] #[derive(Component, Default)]
struct Velocity(Vec2); struct Velocity(Vec2);
#[derive(Component, Default)]
struct SeperationCache(Vec2);
#[derive(Component, Default)]
struct CohesionCache(Vec2);
#[derive(Component, Default)]
struct AlignmentCache(Vec2);
#[derive(Bundle, Default)]
struct BoidCacheBundle {
s_cache: SeperationCache,
c_cache: CohesionCache,
a_cache: AlignmentCache,
}
#[derive(Bundle, Default)] #[derive(Bundle, Default)]
struct BoidBundle { struct BoidBundle {
mesh: MaterialMesh2dBundle<ColorMaterial>, mesh: MaterialMesh2dBundle<ColorMaterial>,
velocity: Velocity, velocity: Velocity,
boid: Boid, boid: Boid,
cache: BoidCacheBundle,
} }
fn seperation(mut boids: Query<(&Transform, &mut SeperationCache), With<Boid>>) {}
fn move_boids(mut boids: Query<(&mut Transform, &Velocity), With<Boid>>, time: Res<Time>) { fn move_boids(mut boids: Query<(&mut Transform, &Velocity), With<Boid>>, time: Res<Time>) {
for (mut transform, velocity) in &mut boids { for (mut transform, velocity) in &mut boids {
transform.translation += velocity.0.extend(0.) * time.delta_seconds(); transform.translation += velocity.0.extend(0.) * time.delta_seconds();