From 5e0cce97f0fd8f535429c74d5616a9a2ee7b5dd5 Mon Sep 17 00:00:00 2001 From: Trevor Settles Date: Mon, 27 Nov 2023 21:41:54 -0700 Subject: [PATCH] feat: read message on client side --- base/src/logic.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/base/src/logic.rs b/base/src/logic.rs index 354fe81..7170a69 100644 --- a/base/src/logic.rs +++ b/base/src/logic.rs @@ -44,7 +44,18 @@ impl Plugin for MultiplayerClientPlugin { .unwrap(), ); - app.add_systems(Update, send_commands.run_if(is_client)); + app.add_systems( + Update, + (send_commands, take_server_messages).run_if(is_client), + ); + } +} + +fn take_server_messages(mut q: Query<(&mut Transform, &NetId)>, mut client: ResMut) { + if let Some(k) = client.receive_message(DefaultChannel::ReliableOrdered) { + let message: MoveEvent = bincode::deserialize(&k).unwrap(); + let mut k = q.iter_mut().find(|m| m.1 == &message.entity).unwrap(); + k.0.translation = message.pos; } }