diff --git a/src/main.rs b/src/main.rs index eeaffa9..4be8ceb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ use bevy_rapier2d::prelude::*; use castles::CastlesPlugin; use health::HealthPlugin; use minions::MinionsPlugin; -use player::LocalPlayerPlugin; +use player::{LocalPlayer, LocalPlayerPlugin}; use racks::RacksPlugin; use teams::TeamsPlugin; @@ -50,6 +50,7 @@ fn main() { }) // --- systems --- .add_systems(Startup, setup) + .add_systems(Update, cameraman) .run(); } @@ -57,3 +58,15 @@ fn setup(mut commands: Commands) { // Camera commands.spawn((Camera2dBundle::default(), Camera {})); } + +fn cameraman( + mut query_camera: Query<&mut Transform, (With, Without)>, + query_player: Query<&Transform, With>, +) { + if let Ok(mut camera_transform) = query_camera.get_single_mut() { + if let Ok(player_transform) = query_player.get_single() { + camera_transform.translation.x = player_transform.translation.x; + camera_transform.translation.y = player_transform.translation.y; + } + } +} diff --git a/src/player.rs b/src/player.rs index ed9178d..f9a26ca 100644 --- a/src/player.rs +++ b/src/player.rs @@ -25,7 +25,7 @@ pub struct Player { } #[derive(Component)] -struct LocalPlayer; +pub struct LocalPlayer; #[derive(Component)] struct Hand;