fix positions of asteroids

This commit is contained in:
yuni 2024-04-01 18:01:51 +02:00
parent 5889aed6fa
commit 71d926ec0f

View file

@ -77,13 +77,17 @@ pub fn setup(
) {
// Generate a bunch of asteriods
let maxdist = 4;
let pi = PI as f64;
let player_x: f64 = -300000.0;
let player_y: f64 = 0.0;
let player_z: f64 = -500000.0;
for i in -maxdist..maxdist {
for j in -maxdist..maxdist {
for k in -maxdist..maxdist {
let offset = 500.0;
let dist = 8e3;
let wobble = dist/2.0;
let (i, j, k) = (i as f32, j as f32, k as f32);
let offset: f64 = 500.0;
let dist: f64 = 8e3;
let wobble: f64 = dist/2.0;
let (i, j, k) = (i as f64, j as f64, k as f64);
let asset = match ((i+j+k) as i32) % 2 {
0 => ASSET_ASTEROID1,
_ => ASSET_ASTEROID2,
@ -96,17 +100,18 @@ pub fn setup(
Collider::sphere(1.0),
SceneBundle {
transform: Transform {
translation: Vec3::new(
offset + dist * i + wobble * (j+k/PI).sin() * (k+j/PI).cos(),
offset + dist * j + wobble * (k+i/PI).sin() * (i+k/PI).cos(),
offset + dist * k + wobble * (i+j/PI).sin() * (j+i/PI).cos(),
),
rotation: Quat::from_rotation_y(-PI / 3.),
scale: Vec3::splat(ASTEROID_SIZE),
..default()
},
scene: asset_server.load(asset),
..default()
},
Rotation::from(Quat::from_rotation_y(-PI / 3.)),
Position::from_xyz(
player_x + offset + dist * i + wobble * (j+k/pi).sin() * (k+j/pi).cos(),
player_y + offset + dist * j + wobble * (k+i/pi).sin() * (i+k/pi).cos(),
player_z + offset + dist * k + wobble * (i+j/pi).sin() * (j+i/pi).cos(),
),
));
}
}