Sync local player too if too far

This commit is contained in:
Sofia 2026-07-18 03:00:45 +03:00
parent e1b7572098
commit 66082a7f04
3 changed files with 11 additions and 2 deletions

View File

@ -294,6 +294,15 @@ impl Game {
if player.id != self.self_id.unwrap_or(0) { if player.id != self.self_id.unwrap_or(0) {
player.set_transform(transform); player.set_transform(transform);
player.set_move_dir(dir); player.set_move_dir(dir);
} else {
if let Some(local_net_transform) = player.get_transform() {
let local_location: Vector3 = local_net_transform.location.into();
let remote_location: Vector3 = transform.location.into();
if local_location.distance_squared_to(remote_location) > 2. {
player.set_transform(transform);
player.set_move_dir(dir);
}
}
} }
} }
} }

View File

@ -1,7 +1,7 @@
use godot::prelude::*; use godot::prelude::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct NetVector3 { pub struct NetVector3 {
pub x: f32, pub x: f32,
pub y: f32, pub y: f32,

View File

@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};
use crate::{net::util::NetVector3, ui::cli::CommandLinePanel}; use crate::{net::util::NetVector3, ui::cli::CommandLinePanel};
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct NetPlayerTransform { pub struct NetPlayerTransform {
pub location: NetVector3, pub location: NetVector3,
pub rotation: NetVector3, pub rotation: NetVector3,