diff --git a/Assets/Mirror/Components/ForecastRigidbody/ForecastRigidbody.cs b/Assets/Mirror/Components/ForecastRigidbody/ForecastRigidbody.cs index a6d15a411..8204ec9a3 100644 --- a/Assets/Mirror/Components/ForecastRigidbody/ForecastRigidbody.cs +++ b/Assets/Mirror/Components/ForecastRigidbody/ForecastRigidbody.cs @@ -156,7 +156,6 @@ protected void BeginPredicting() } double blendingStartTime; - float BlendingElapsedTime() => (float)(NetworkTime.time - blendingStartTime); protected void BeginBlending() { state = ForecastState.BLENDING; @@ -252,11 +251,11 @@ void FixedUpdateClient() { // physics movements need to be done in FixedUpdate. - if (state == ForecastState.PREDICTING) - { - // PREDICTING checks state, which happens in update() - } - else if (state == ForecastState.BLENDING) + // PREDICTING checks state, which happens in update() + // if (state == ForecastState.PREDICTING) + // { + // } + if (state == ForecastState.BLENDING) { // TODO snapshot interpolation @@ -268,14 +267,15 @@ void FixedUpdateClient() } // sample the blending curve to find out how much to blend right now - float blendingElapsed = BlendingElapsedTime(); + + float blendingElapsed = (float)(NetworkTime.time - blendingStartTime); float relativeElapsed = blendingElapsed / blendingTime; float p = blendingCurve.Evaluate(relativeElapsed); // Debug.Log($"{name} BLENDING @ {blendingElapsed:F2} / {blendingTime:F2} => {(p*100):F0}%"); - // blend local position to remote position - Vector3 currentPosition = predictedRigidbody.position; - Quaternion currentRotation = predictedRigidbody.rotation; + // blend local position to remote position. + // getting both at once is fastest. + tf.GetPositionAndRotation(out Vector3 currentPosition, out Quaternion currentRotation); // smoothly interpolate to the target position. // speed relative to how far away we are. @@ -305,10 +305,10 @@ void FixedUpdateClient() BeginFollowing(); } } - else if (state == ForecastState.FOLLOWING) - { - // FOLLOWING sets Transform, which happens in Update(). - } + // FOLLOWING sets Transform, which happens in Update(). + // else if (state == ForecastState.FOLLOWING) + // { + // } } void FixedUpdate() diff --git a/Assets/Mirror/Examples/BenchmarkPrediction/Readme.md b/Assets/Mirror/Examples/BenchmarkPrediction/Readme.md index ccd787ff8..82261ab7e 100644 --- a/Assets/Mirror/Examples/BenchmarkPrediction/Readme.md +++ b/Assets/Mirror/Examples/BenchmarkPrediction/Readme.md @@ -22,4 +22,4 @@ Predicted: 2024-03-15: 625 FPS Client, 1700 FPS Server // Vector3.MoveTowardsCustom() 2024-03-18: 628 FPS Client, 1700 FPS Server // removed O(N) insertion from CorrectHistory() 2024-03-28: 800 FPS Client, 1700 FPS Server // FAST mode prediction - 2024-04-04: 570 FPS Client, 1700 FPS Server // Forecasting & hand-off + 2024-04-04: 580 FPS Client, 1700 FPS Server // Forecasting & hand-off