configurable frames

This commit is contained in:
mischa 2023-11-17 11:00:26 +01:00
parent 6f9cac6013
commit 61b3f40e7e

View File

@ -84,6 +84,8 @@ public class PredictedRigidbody : NetworkBehaviour
[Header("Smoothing")] [Header("Smoothing")]
[Tooltip("Configure how to apply the corrected state.")] [Tooltip("Configure how to apply the corrected state.")]
public CorrectionMode correctionMode = CorrectionMode.Move; 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; Vector3 deltaCorrection_Position = Vector3.zero;
[Header("Debugging")] [Header("Debugging")]
@ -138,9 +140,8 @@ void ApplyDeltaCorrection()
if (deltaCorrection_Position != Vector3.zero) if (deltaCorrection_Position != Vector3.zero)
{ {
// apply only a little bit each frame // apply only a little bit each frame
// TODO don't hardcode the amount // TODO depend on deltatime instead of hard frames
// TODO depend on deltatime? Vector3 step = deltaCorrection_Position / deltaCorrectionFrames;
Vector3 step = deltaCorrection_Position / 10;
rb.MovePosition(rb.position + step); rb.MovePosition(rb.position + step);
deltaCorrection_Position -= step; deltaCorrection_Position -= step;