From 61b3f40e7eacc6c6f8e331be009def7dfe8d56e5 Mon Sep 17 00:00:00 2001 From: mischa Date: Fri, 17 Nov 2023 11:00:26 +0100 Subject: [PATCH] configurable frames --- .../Components/PredictedRigidbody/PredictedRigidbody.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs b/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs index 0f258c61e..693d1a526 100644 --- a/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs +++ b/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs @@ -84,6 +84,8 @@ public class PredictedRigidbody : NetworkBehaviour [Header("Smoothing")] [Tooltip("Configure how to apply the corrected state.")] public CorrectionMode correctionMode = CorrectionMode.Move; + [Range(1, 60)] // 0 would never correct, and too high would take too long. assuming 60 FPS, the limit here is 1 second + public int deltaCorrectionFrames = 10; // TODO depend on delta time / speed later in case frame rate varies Vector3 deltaCorrection_Position = Vector3.zero; [Header("Debugging")] @@ -138,9 +140,8 @@ void ApplyDeltaCorrection() if (deltaCorrection_Position != Vector3.zero) { // apply only a little bit each frame - // TODO don't hardcode the amount - // TODO depend on deltatime? - Vector3 step = deltaCorrection_Position / 10; + // TODO depend on deltatime instead of hard frames + Vector3 step = deltaCorrection_Position / deltaCorrectionFrames; rb.MovePosition(rb.position + step); deltaCorrection_Position -= step;