From a24588e6a7220a25d9dd2fa460bf8fcf1a49a38b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Cor=C3=A9n?= <2108U9@gmail.com> Date: Sun, 4 Mar 2018 19:30:56 +0100 Subject: [PATCH] Fixed issues with lag compensation --- MLAPI/MonoBehaviours/Core/TrackedObject.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/MLAPI/MonoBehaviours/Core/TrackedObject.cs b/MLAPI/MonoBehaviours/Core/TrackedObject.cs index 29f393f..9f59278 100644 --- a/MLAPI/MonoBehaviours/Core/TrackedObject.cs +++ b/MLAPI/MonoBehaviours/Core/TrackedObject.cs @@ -18,17 +18,18 @@ namespace MLAPI.MonoBehaviours.Core savedPosition = transform.position; savedRotation = transform.rotation; float currentTime = Time.time; - float targetTime = Time.time - secondsAgo; + float targetTime = currentTime - secondsAgo; float previousTime = 0; float nextTime = 0; - for (int i = 1; i < Framekeys.Count - 1; i++) + for (int i = 1; i < Framekeys.Count; i++) { - if(Framekeys[i - 1] > targetTime && Framekeys[i] <= targetTime) + if (Framekeys[i - 1] <= targetTime && Framekeys[i] >= targetTime) { previousTime = Framekeys[i]; nextTime = Framekeys[i + 1]; break; } + } float timeBetweenFrames = nextTime - previousTime; @@ -59,7 +60,7 @@ namespace MLAPI.MonoBehaviours.Core float currentTime = Time.time; for (int i = 0; i < Framekeys.Count; i++) { - if (currentTime - Framekeys[i] <= NetworkingManager.singleton.NetworkConfig.SecondsHistory) + if (currentTime - Framekeys[i] >= NetworkingManager.singleton.NetworkConfig.SecondsHistory) { for (int j = 0; j < i; j++) { @@ -74,7 +75,7 @@ namespace MLAPI.MonoBehaviours.Core position = transform.position, rotation = transform.rotation }); - Framekeys.Add(Time.frameCount); + Framekeys.Add(Time.time); } } }