Fix high latency, simulate 1000 ping

This commit is contained in:
Sofia 2026-08-08 23:44:06 +03:00
parent 45b7e69006
commit 953df8d2d0
2 changed files with 23 additions and 2 deletions

View File

@ -1079,7 +1079,12 @@ impl Game {
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. {
let max_distance = (player.data.ping as f32 / 1000.)
* (player.get_move_speed() + player.get_y_speed())
* 2.;
if local_location.distance_to(remote_location) > max_distance {
player.set_transform(transform);
}
}
@ -1690,6 +1695,22 @@ impl Player {
None
}
}
fn get_move_speed(&self) -> f32 {
if let Some(character) = &self.character {
character.dyn_bind().get_move_speed()
} else {
0.
}
}
fn get_y_speed(&self) -> f32 {
if let Some(character) = &self.character {
character.dyn_bind().get_y_speed()
} else {
0.
}
}
}
#[derive(Debug, Default, Serialize, Deserialize, Clone)]

View File

@ -271,7 +271,7 @@ impl NetworkManager {
None,
PeerConfig::default()
.with_identifier(NetworkManager::identifier())
.with_additional_ping(Duration::from_millis(100)),
.with_additional_ping(Duration::from_millis(1000)),
);
match peer {
Ok(mut peer) => {