random boid angle
This commit is contained in:
parent
ed8c679e57
commit
3d512db39b
1 changed files with 7 additions and 1 deletions
|
@ -63,6 +63,8 @@ fn alignment(mut boids: Query<(Entity, &Transform, &mut SeperationAcceleration),
|
||||||
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();
|
||||||
|
transform.rotation =
|
||||||
|
Quat::from_rotation_z(velocity.0.to_angle() - std::f32::consts::FRAC_PI_2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,9 +80,13 @@ fn setup(
|
||||||
let upper_bound = 100.;
|
let upper_bound = 100.;
|
||||||
|
|
||||||
for i in 0..100 {
|
for i in 0..100 {
|
||||||
|
use std::f32::consts::TAU;
|
||||||
|
|
||||||
let x = small_rng.gen_range(lower_bound..=upper_bound);
|
let x = small_rng.gen_range(lower_bound..=upper_bound);
|
||||||
let y = small_rng.gen_range(lower_bound..=upper_bound);
|
let y = small_rng.gen_range(lower_bound..=upper_bound);
|
||||||
|
|
||||||
|
let angle = small_rng.gen_range(-TAU..=TAU);
|
||||||
|
|
||||||
commands.spawn(BoidBundle {
|
commands.spawn(BoidBundle {
|
||||||
mesh: MaterialMesh2dBundle {
|
mesh: MaterialMesh2dBundle {
|
||||||
mesh: boid_mesh.0.clone(),
|
mesh: boid_mesh.0.clone(),
|
||||||
|
@ -89,7 +95,7 @@ fn setup(
|
||||||
.with_translation(Vec3::new(x, y, 0.)),
|
.with_translation(Vec3::new(x, y, 0.)),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
velocity: Velocity(Vec2::Y * 100.),
|
velocity: Velocity(Vec2::from_angle(angle) * 100.),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue