Follow player camera
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user