Follow player camera

This commit is contained in:
2026-09-15 23:50:06 +02:00
parent fe35a17901
commit 82b8bbb699
+27
View File
@@ -0,0 +1,27 @@
use bevy::{prelude::*, winit::UpdateMode};
use crate::player::Player;
#[derive(Component)]
struct Camera;
fn spawn_camera(mut commands: Commands) {
commands.spawn(Camera2d);
}
// Follow the player with the camera
fn follow_player(
player: Single<&Transform, With<Player>>,
mut camera: Single<&mut Transform, With<Camera>>,
) {
camera.translation = player.translation;
}
struct CameraPlugin;
impl Plugin for CameraPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, spawn_camera)
.add_systems(Update, follow_player);
}
}