use avian3d::prelude::*;
use bevy::prelude::*;
use bevy_egui::EguiPlugin;
use bevy_inspector_egui::quick::WorldInspectorPlugin;
fn main() {
let mut app = App::new();
app.add_plugins(DefaultPlugins);
app.add_plugins((PhysicsPlugins::default(), PhysicsDebugPlugin::default()));
app.add_plugins((
EguiPlugin {
enable_multipass_for_primary_context: true,
},
WorldInspectorPlugin::default(),
));
app.add_systems(Startup, setup);
app.run();
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// Static physics object with a collision shape
commands.spawn((
RigidBody::Static,
Collider::cylinder(4.0, 0.1),
Mesh3d(meshes.add(Cylinder::new(4.0, 0.1))),
MeshMaterial3d(materials.add(Color::WHITE)),
));
// Dynamic physics object with a collision shape and initial angular velocity
commands.spawn((
RigidBody::Dynamic,
Collider::cuboid(1.0, 1.0, 1.0),
AngularVelocity(Vec3::new(2.5, 3.5, 1.5)),
Mesh3d(meshes.add(Cuboid::from_length(1.0))),
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
Transform::from_xyz(0.0, 4.0, 0.0),
));
// Light
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
},
Transform::from_xyz(4.0, 8.0, 4.0),
));
// Camera
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Dir3::Y),
));
}