added a timer to spawning cubes
This commit is contained in:
@@ -21,26 +21,27 @@ pub fn setup_scene(
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
/*
|
||||
* Ground
|
||||
* workbench plane
|
||||
*/
|
||||
let ground_size = 2.5;
|
||||
let ground_height = 0.1;
|
||||
let ground_height = 0.825;
|
||||
let ground_thickness = 0.05;
|
||||
// plane
|
||||
commands.spawn((
|
||||
PbrBundle {
|
||||
mesh: meshes.add(shape::Plane::from_size(5.0).into()),
|
||||
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
|
||||
transform: Transform::from_xyz(0.0, -ground_height, 0.0),
|
||||
transform: Transform::from_xyz(0.0, ground_height, 0.0),
|
||||
..default()
|
||||
},
|
||||
Collider::cuboid(ground_size, ground_height, ground_size),
|
||||
Collider::cuboid(ground_size, ground_thickness, ground_size),
|
||||
));
|
||||
// cube
|
||||
commands.spawn((
|
||||
PbrBundle {
|
||||
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
|
||||
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
|
||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
transform: Transform::from_xyz(0.0, 1.0, 0.0),
|
||||
..default()
|
||||
},
|
||||
RigidBody::Dynamic,
|
||||
@@ -74,45 +75,4 @@ pub fn setup_scene(
|
||||
),
|
||||
..default()
|
||||
},));
|
||||
}
|
||||
|
||||
pub fn setup_physics(mut commands: Commands) {
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
let num = 8;
|
||||
let rad = 1.0;
|
||||
|
||||
let shift = rad * 2.0 + rad;
|
||||
let centerx = shift * (num / 2) as f32;
|
||||
let centery = shift / 2.0;
|
||||
let centerz = shift * (num / 2) as f32;
|
||||
|
||||
let mut offset = -(num as f32) * (rad * 2.0 + rad) * 0.5;
|
||||
let mut color = 0;
|
||||
let colors = [
|
||||
Color::hsl(220.0, 1.0, 0.3),
|
||||
Color::hsl(180.0, 1.0, 0.3),
|
||||
Color::hsl(260.0, 1.0, 0.7),
|
||||
];
|
||||
|
||||
for j in 0usize..20 {
|
||||
for i in 0..num {
|
||||
for k in 0usize..num {
|
||||
let x = i as f32 * shift - centerx + offset;
|
||||
let y = j as f32 * shift + centery + 3.0;
|
||||
let z = k as f32 * shift - centerz + offset;
|
||||
color += 1;
|
||||
|
||||
commands.spawn((
|
||||
TransformBundle::from(Transform::from_xyz(x, y, z)),
|
||||
RigidBody::Dynamic,
|
||||
Collider::cuboid(rad, rad, rad),
|
||||
ColliderDebugColor(colors[color % 3]),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
offset -= 0.05 * rad * (num as f32 - 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user