use bevy::sprite::MaterialMesh2dBundle; use bevy::{prelude::*, DefaultPlugins}; use bevy_cameraman::{CameraBundle, CameraDebugPlugin, CameraPlugin, Cameraman, Target}; fn main() { let mut app = App::new(); app.add_plugins(DefaultPlugins) // --- camera --- .add_plugins(( CameraPlugin, // CameraDebugPlugin, // uncomment this to see debug mode )) // --- systems --- .add_systems(Startup, (setup_example, setup_rectangles)) .add_systems(Update, (keyboard_movements, update_axes)) .run(); } #[derive(Component)] struct LocalPlayer; fn setup_example( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { // 1. spawn your entity to follow let entity = commands .spawn(( MaterialMesh2dBundle { mesh: meshes.add(shape::Circle::new(30.).into()).into(), material: materials.add(ColorMaterial::from(Color::rgb(0.8, 0.3, 0.3))), transform: Transform::from_translation(Vec3::new(-150., 0., 0.)), ..default() }, LocalPlayer {}, // you need this to tell the camera to focus this entity Target, )) .id(); // 2. spawn your cameraman and make it follow previou entity // you should play with the cameraman values! commands.spawn(CameraBundle::new( Cameraman::new(entity, Vec2::new(50.0, 20.0), Vec3::ONE * 0.8), Camera2dBundle::default(), )); } // -- for the demo -- // fn setup_rectangles( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { commands.spawn(MaterialMesh2dBundle { mesh: meshes.add(shape::Circle::new(30.).into()).into(), material: materials.add(ColorMaterial::from(Color::rgb(0.3, 0.3, 0.8))), transform: Transform::from_translation(Vec3::new(-150., -200., 0.)), ..default() }); commands.spawn(MaterialMesh2dBundle { mesh: meshes.add(shape::Circle::new(30.).into()).into(), material: materials.add(ColorMaterial::from(Color::rgb(0.3, 0.3, 0.8))), transform: Transform::from_translation(Vec3::new(300., 120., 0.)), ..default() }); } fn keyboard_movements( time: Res