From b09b4a6c8854d8c253e2129b57a9637f4c362fbe Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Sun, 24 Mar 2024 15:55:06 +0100 Subject: feat: camera controls --- src/client.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 16 deletions(-) (limited to 'src/client.rs') diff --git a/src/client.rs b/src/client.rs index d536dce..bff66cd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -57,6 +57,12 @@ struct MyFaction(pub Faction); #[derive(Resource)] struct Attack(Option); +#[derive(Resource, Default)] +struct CameraControls { + pub direction: Vec2, + pub locked: bool, +} + struct ClientPlugin { pub server_addr: Option, pub client_id: u64, @@ -71,6 +77,7 @@ impl Plugin for ClientPlugin { .insert_resource(MyChampion(self.champion)) .insert_resource(MyFaction(self.faction)) .insert_resource(Attack(None)) + .insert_resource(CameraControls::default()) .add_plugins(NetworkPlugin { server_addr: self.server_addr.clone(), client_id: self.client_id, @@ -105,7 +112,14 @@ impl Plugin for ClientPlugin { .chain(), ), ) - .add_systems(Update, move_camera) + .add_systems( + Update, + ( + control_camera, + lock_camera, + move_camera.after(control_camera).after(lock_camera), + ), + ) .add_systems( FixedPreUpdate, buffer_input @@ -872,26 +886,55 @@ fn health_indicator_despawn( } } -const CAMERA_MOVEMENT_SPEED: f32 = 100.; - fn move_camera( mut cameras: Query<&mut Transform, With>, - players: Query<(&PlayerId, &PlayerPosition, &Shape)>, - client_id: Res, time: Res