Camera modifs
This commit is contained in:
+6
-8
@@ -1,9 +1,7 @@
|
|||||||
use bevy::{prelude::*, winit::UpdateMode};
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::player::Player;
|
use crate::player::Player;
|
||||||
|
use crate::player::move_player;
|
||||||
#[derive(Component)]
|
|
||||||
struct Camera;
|
|
||||||
|
|
||||||
fn spawn_camera(mut commands: Commands) {
|
fn spawn_camera(mut commands: Commands) {
|
||||||
commands.spawn(Camera2d);
|
commands.spawn(Camera2d);
|
||||||
@@ -11,17 +9,17 @@ fn spawn_camera(mut commands: Commands) {
|
|||||||
|
|
||||||
// Follow the player with the camera
|
// Follow the player with the camera
|
||||||
fn follow_player(
|
fn follow_player(
|
||||||
player: Single<&Transform, With<Player>>,
|
player: Single<&Transform, (With<Player>, Without<Camera2d>)>,
|
||||||
mut camera: Single<&mut Transform, With<Camera>>,
|
mut camera: Single<&mut Transform, (With<Camera2d>, Without<Player>)>,
|
||||||
) {
|
) {
|
||||||
camera.translation = player.translation;
|
camera.translation = player.translation;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CameraPlugin;
|
pub struct CameraPlugin;
|
||||||
|
|
||||||
impl Plugin for CameraPlugin {
|
impl Plugin for CameraPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Startup, spawn_camera)
|
app.add_systems(Startup, spawn_camera)
|
||||||
.add_systems(Update, follow_player);
|
.add_systems(Update, follow_player.after(move_player));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user