2024-07-29 14:33:14 -05:00
|
|
|
use bevy::prelude::*;
|
2024-07-29 16:29:39 -05:00
|
|
|
use bevy::render::camera::Camera;
|
2023-12-23 16:50:08 -06:00
|
|
|
|
2024-07-29 16:29:39 -05:00
|
|
|
pub fn startup(mut commands: Commands) {
|
2024-07-31 15:37:11 -05:00
|
|
|
let mut bundle = (Camera2dBundle::default(), IsDefaultUiCamera);
|
2024-07-31 15:55:17 -05:00
|
|
|
bundle.0.projection = OrthographicProjection {
|
|
|
|
near: f32::MIN,
|
|
|
|
far: f32::MAX,
|
|
|
|
scale: 1.,
|
|
|
|
..default()
|
|
|
|
};
|
|
|
|
// bundle.0.transform.translation.z = f32::MAX;
|
2024-07-31 15:37:11 -05:00
|
|
|
bundle.0.projection.scale = 1.;
|
2023-12-20 13:24:16 -06:00
|
|
|
commands.spawn(bundle);
|
|
|
|
}
|
2023-12-23 16:50:08 -06:00
|
|
|
|
2024-07-29 16:29:39 -05:00
|
|
|
#[derive(Component, Debug)]
|
|
|
|
pub struct Watched;
|
|
|
|
|
|
|
|
pub fn update(
|
|
|
|
watched: Query<&Transform, With<Watched>>,
|
|
|
|
mut camera: Query<&mut Transform, (With<Camera>, Without<Watched>)>,
|
2024-07-24 17:03:22 -05:00
|
|
|
) {
|
2024-07-29 16:29:39 -05:00
|
|
|
if let Ok(mut camera) = camera.get_single_mut() {
|
|
|
|
if let Ok(watched) = watched.get_single() {
|
2024-07-29 16:54:43 -05:00
|
|
|
camera.translation.x = watched.translation.x;
|
|
|
|
camera.translation.y = watched.translation.y;
|
2024-07-29 16:29:39 -05:00
|
|
|
} else {
|
|
|
|
camera.translation = Vec3::ZERO;
|
|
|
|
}
|
2024-07-24 17:03:22 -05:00
|
|
|
}
|
|
|
|
}
|