mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 14:29:25 +00:00
[RelativeSync] Attempt to fix interpolation
This commit is contained in:
parent
ca7df56e76
commit
c46bc61619
2 changed files with 18 additions and 10 deletions
|
@ -7,6 +7,9 @@ namespace NAK.RelativeSync.Components;
|
||||||
public class RelativeSyncController : MonoBehaviour
|
public class RelativeSyncController : MonoBehaviour
|
||||||
{
|
{
|
||||||
private static float MaxMagnitude = 750000000000f;
|
private static float MaxMagnitude = 750000000000f;
|
||||||
|
|
||||||
|
private float _updateInterval = 0.05f;
|
||||||
|
private float _lastUpdate;
|
||||||
|
|
||||||
private string _userId;
|
private string _userId;
|
||||||
private PuppetMaster puppetMaster { get; set; }
|
private PuppetMaster puppetMaster { get; set; }
|
||||||
|
@ -41,7 +44,7 @@ public class RelativeSyncController : MonoBehaviour
|
||||||
|
|
||||||
if (_relativeSyncMarker == null)
|
if (_relativeSyncMarker == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Animator animator = puppetMaster._animator;
|
Animator animator = puppetMaster._animator;
|
||||||
if (animator == null)
|
if (animator == null)
|
||||||
return;
|
return;
|
||||||
|
@ -62,11 +65,9 @@ public class RelativeSyncController : MonoBehaviour
|
||||||
relativeHipPos = Quaternion.Inverse(worldRootRot) * (hipPos - worldRootPos);
|
relativeHipPos = Quaternion.Inverse(worldRootRot) * (hipPos - worldRootPos);
|
||||||
relativeHipRot = Quaternion.Inverse(worldRootRot) * hipRot;
|
relativeHipRot = Quaternion.Inverse(worldRootRot) * hipRot;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: this is fucked and idk why, is technically slightly differing sync rates,
|
float lerp = Mathf.Min((Time.time - _lastUpdate) / _updateInterval, 1f);
|
||||||
// but even reimplementing dynamic tps here didnt fix the jitter
|
|
||||||
float lerp = netIkController.GetLerpSpeed();
|
|
||||||
|
|
||||||
Vector3 targetLocalPosition = _relativeSyncData.LocalRootPosition;
|
Vector3 targetLocalPosition = _relativeSyncData.LocalRootPosition;
|
||||||
Quaternion targetLocalRotation = Quaternion.Euler(_relativeSyncData.LocalRootRotation);
|
Quaternion targetLocalRotation = Quaternion.Euler(_relativeSyncData.LocalRootRotation);
|
||||||
Transform targetTransform = _relativeSyncMarker.transform;
|
Transform targetTransform = _relativeSyncMarker.transform;
|
||||||
|
@ -109,9 +110,6 @@ public class RelativeSyncController : MonoBehaviour
|
||||||
hipTrans.position = transform.position + transform.rotation * relativeHipPos;
|
hipTrans.position = transform.position + transform.rotation * relativeHipPos;
|
||||||
hipTrans.rotation = transform.rotation * relativeHipRot;
|
hipTrans.rotation = transform.rotation * relativeHipRot;
|
||||||
}
|
}
|
||||||
|
|
||||||
_lastSyncData.LocalRootPosition = targetLocalPosition;
|
|
||||||
_lastSyncData.LocalRootRotation = targetLocalRotation.eulerAngles;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Unity Events
|
#endregion Unity Events
|
||||||
|
@ -142,6 +140,16 @@ public class RelativeSyncController : MonoBehaviour
|
||||||
|
|
||||||
public void SetRelativePositions(Vector3 position, Vector3 rotation)
|
public void SetRelativePositions(Vector3 position, Vector3 rotation)
|
||||||
{
|
{
|
||||||
|
// calculate update interval
|
||||||
|
float prevUpdate = _lastUpdate;
|
||||||
|
_lastUpdate = Time.time;
|
||||||
|
_updateInterval = _lastUpdate - prevUpdate;
|
||||||
|
|
||||||
|
// cycle last sync data
|
||||||
|
_lastSyncData.LocalRootPosition = _relativeSyncData.LocalRootPosition;
|
||||||
|
_lastSyncData.LocalRootRotation = _relativeSyncData.LocalRootRotation;
|
||||||
|
|
||||||
|
// set new sync data
|
||||||
_relativeSyncData.LocalRootPosition = position;
|
_relativeSyncData.LocalRootPosition = position;
|
||||||
_relativeSyncData.LocalRootRotation = rotation;
|
_relativeSyncData.LocalRootRotation = rotation;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"None"
|
"None"
|
||||||
],
|
],
|
||||||
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r26/RelativeSync.dll",
|
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r27/RelativeSync.dll",
|
||||||
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/RelativeSync/",
|
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/RelativeSync/",
|
||||||
"changelog": "- Initial Release",
|
"changelog": "- Initial Release",
|
||||||
"embedcolor": "#507e64"
|
"embedcolor": "#507e64"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue