Add PingBias

This commit is contained in:
Sofia 2020-08-08 04:44:45 +03:00
parent 7cbcc1de96
commit afaed03bd5
3 changed files with 18 additions and 4 deletions

View File

@ -119,6 +119,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
} else {
Ping = Instances.Server.PingInterval + 0.001f;
}
UpdatePingBias();
}
}
}
@ -144,6 +145,15 @@ namespace NeonTea.Quakeball.Networking.Instances {
}
}
private void UpdatePingBias() {
foreach (NetPlayer p in Players.Values) {
if (p.Id != LocalPlayer.Id) {
p.Controlled.PingBias = Ping;
}
}
}
public override void UpdateLocalPlayer() {
if (SelfIdentified && Server != null) {
PlayerUpdatePckt pckt = LocalPlayer.Controlled.CreateUpdatePacket();

View File

@ -113,10 +113,14 @@ namespace NeonTea.Quakeball.Networking.Instances {
if (!ping.ServerReceived) {
ping.ServerReceived = true;
Peer.SendReliable(conn.uid, ping);
NetPlayer p = Players[conn.uid];
if (ping.Identifier == LastPingIdent) {
Players[conn.uid].Ping = Time.time - LastSentPing;
p.Ping = Time.time - LastSentPing;
} else {
Players[conn.uid].Ping = PingInterval + 0.001f;
p.Ping = PingInterval + 0.001f;
}
if (p.Controlled != null) {
p.Controlled.PingBias = p.Ping;
}
}
}

View File

@ -10,7 +10,7 @@ namespace NeonTea.Quakeball.Players {
/// <summary>The duration after running off a cliff, during which the player should still be considered grounded.</summary>
public float CoyoteTime;
public float CoyoteTimePingBias;
public float PingBias;
/// <summary>How often should the player's movement be updated? Used by Local and Remote -Player classes.</summary>
public float UpdateFrequency = 1f;
@ -121,7 +121,7 @@ namespace NeonTea.Quakeball.Players {
}
public bool Jump() {
bool IsCoyoteTime = Time.time - GroundedTime <= CoyoteTime + CoyoteTimePingBias;
bool IsCoyoteTime = Time.time - GroundedTime <= CoyoteTime + PingBias;
if (IsCoyoteTime || IsGrounded()) {
GravitationalVelocity = Vector3.up * MoveStyle.JumpVelocity;
Vector3 Pos = transform.position;