aboutsummaryrefslogtreecommitdiffstats
path: root/src/client.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/client.rs')
-rw-r--r--src/client.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/client.rs b/src/client.rs
index 6fa6ff1..7f1220e 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -94,6 +94,7 @@ impl Plugin for ClientPlugin {
.chain(),
),
)
+ .add_systems(Update, move_camera)
.add_systems(
FixedPreUpdate,
buffer_input.in_set(InputSystemSet::BufferInputs),
@@ -790,3 +791,27 @@ fn health_indicator_despawn(
commands.entity(entity).despawn();
}
}
+
+const CAMERA_MOVEMENT_SPEED: f32 = 100.;
+
+fn move_camera(
+ mut cameras: Query<&mut Transform, With<Camera>>,
+ players: Query<(&PlayerId, &PlayerPosition, &Shape)>,
+ client_id: Res<ClientId>,
+ time: Res<Time>,
+) {
+ let Some(player_position) = player_position(&client_id, &players) else {
+ return;
+ };
+ let dt = time.delta().as_secs_f32();
+ for mut transform in cameras.iter_mut() {
+ let direction = (Vec3::new(
+ player_position.0.x,
+ player_position.0.y,
+ transform.translation.z,
+ ) - transform.translation)
+ .normalize_or_zero();
+ transform.translation +=
+ (dt * CAMERA_MOVEMENT_SPEED).min(direction.length()) * direction.normalize_or_zero();
+ }
+}