Skip to content

Commit cf3f591

Browse files
committed
Update lag comp rigidbody, update send rate
1 parent df5f5b0 commit cf3f591

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

Runtime/Code/Network/Simulation/AirshipLagCompensatedEntity.cs renamed to Runtime/Code/Network/Simulation/AirshipLagCompensatedRigidbody.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using Mirror;
33
using UnityEngine;
4+
using UnityEngine.Serialization;
45

56
namespace Code.Network.Simulation
67
{
@@ -11,27 +12,38 @@ struct RigidbodySnapshot
1112
public Vector3 angularVelocity;
1213
public Quaternion rotation;
1314
}
14-
15+
1516
/**
1617
* This component is used to allow for lag compensation to operate on rigidbodies controlled by the server.
1718
*/
18-
public class AirshipLagCompensatedEntity: NetworkBehaviour
19+
public class AirshipLagCompensatedRigidbody : NetworkBehaviour
1920
{
20-
[Tooltip("Time in seconds kept in history.")]
21-
[Range(0, 1)]
21+
[Tooltip("Time kept in history in seconds in seconds.")] [Range(0, 1)]
2222
public float historySize = 1;
2323

24+
[Tooltip(
25+
"Amount of ticks buffered on the client before rendering. " +
26+
"It's important to get this number correct as it controls the additional rollback time required to correctly " +
27+
"produce the client's view of the world during lag compensation. It should match the number of physics updates " +
28+
"you wait before rendering the object. By default, Airship has 2 updates buffered by Mirror.")]
29+
public uint bufferSizeMultiplier = 2;
30+
31+
[Tooltip("The send rate being used to update this rigidbodies positions. This is used to calculate the " +
32+
"additional rollback time required to produce the client's view of the world during lag compensation. " +
33+
"It should match the number of updates sent per second. Airship uses a default send rate of 50 for Mirror.")]
34+
public uint updateSendRate = 50;
35+
2436
private Rigidbody rb;
2537
private History<RigidbodySnapshot> history;
26-
38+
2739
private void Awake()
2840
{
2941
// Lag compensation only occurs on the server, so this component only operates on the server.
3042
if (isServer)
3143
{
3244
rb = this.GetComponent<Rigidbody>();
3345
var snapshots = historySize / Time.fixedDeltaTime;
34-
history = new History<RigidbodySnapshot>((int) Math.Ceiling(snapshots));
46+
history = new History<RigidbodySnapshot>((int)Math.Ceiling(snapshots));
3547
AirshipSimulationManager.OnCaptureSnapshot += this.CaptureSnapshot;
3648
AirshipSimulationManager.OnSetSnapshot += this.SetSnapshot;
3749
AirshipSimulationManager.OnLagCompensationCheck += this.LagCompensationCheck;
@@ -71,8 +83,8 @@ private void SetSnapshot(double time)
7183

7284
private void LagCompensationCheck(int clientId, double time, double latency)
7385
{
74-
// TODO: configure buffer time
75-
var bufferedTime = time - latency - (3f / Time.fixedDeltaTime);
86+
var sendRate = 1f / this.updateSendRate;
87+
var bufferedTime = time - latency - (this.bufferSizeMultiplier * sendRate);
7688
this.SetSnapshot(bufferedTime);
7789
}
7890
}

Runtime/Code/Network/Simulation/AirshipLagCompensatedEntity.cs.meta renamed to Runtime/Code/Network/Simulation/AirshipLagCompensatedRigidbody.cs.meta

File renamed without changes.

Runtime/Prefabs/Network.prefab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ MonoBehaviour:
5353
runInBackground: 1
5454
headlessStartMode: 0
5555
editorAutoStart: 0
56-
sendRate: 60
56+
sendRate: 50
5757
autoStartServerBuild: 0
5858
autoConnectClientBuild: 0
5959
offlineScene:

0 commit comments

Comments
 (0)