use std::f32::consts::PI; use bevy::prelude::*; use bevy_dolly::{drivers::follow::MovableLookAt, prelude::*}; #[derive(Component)] struct MainCamera; fn main() { App::new() .insert_resource(Msaa::default()) .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .add_systems( Update, ( Dolly::::update_active, update_camera, rotator_system, ), ) .run(); } /// set up a simple 3D scene fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, asset_server: Res, ) { // plane commands.spawn(PbrBundle { mesh: meshes.add(Plane3d::default().mesh().size(5., 5.)), material: materials.add(Color::srgb(0.3, 0.5, 0.3)), ..default() }); let start_pos = Vec3::new(0., 0., 0.); commands.spawn(( Rotates, SceneBundle { scene: asset_server.load("poly_dolly.gltf#Scene0"), transform: Transform { translation: Vec3::new(0., 0.2, 0.), ..default() }, ..default() }, )); commands.spawn(( MainCamera, Rig::builder() .with(MovableLookAt::from_position_target(start_pos)) .build(), Camera3dBundle { transform: Transform::from_xyz(-2.0, 1., 5.0).looking_at(Vec3::ZERO, Vec3::Y), ..default() }, )); // light commands.spawn(PointLightBundle { transform: Transform::from_xyz(4.0, 8.0, 4.0), ..default() }); } fn update_camera(q0: Query<&Transform, With>, mut q1: Query<&mut Rig>) { let player = q0.single().to_owned(); let mut rig = q1.single_mut(); rig.driver_mut::() .set_position_target(player.translation, player.rotation); } #[derive(Component)] struct Rotates; fn rotator_system(time: Res