corrections
This commit is contained in:
+8
-5
@@ -3,14 +3,17 @@ use bevy::prelude::*;
|
||||
use crate::player::Player;
|
||||
use crate::player::move_player;
|
||||
|
||||
fn spawn_camera(mut commands: Commands) {
|
||||
commands.spawn(Camera2d);
|
||||
#[derive(Component)]
|
||||
pub struct MainCamera;
|
||||
|
||||
fn spawn_main_camera(mut commands: Commands) {
|
||||
commands.spawn((Camera2d, MainCamera));
|
||||
}
|
||||
|
||||
// Follow the player with the camera
|
||||
fn follow_player(
|
||||
player: Single<&Transform, (With<Player>, Without<Camera2d>)>,
|
||||
mut camera: Single<&mut Transform, (With<Camera2d>, Without<Player>)>,
|
||||
player: Single<&Transform, (With<Player>, Without<MainCamera>)>,
|
||||
mut camera: Single<&mut Transform, (With<MainCamera>, Without<Player>)>,
|
||||
// time: Res<Time>,
|
||||
) {
|
||||
camera.translation.y = player.translation.y; // without delay
|
||||
@@ -22,7 +25,7 @@ pub struct CameraPlugin;
|
||||
|
||||
impl Plugin for CameraPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, spawn_camera)
|
||||
app.add_systems(Startup, spawn_main_camera)
|
||||
.add_systems(Update, follow_player.after(move_player));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user