From 3354363eae447d9a2530a71aaa0ba631eb3a260e Mon Sep 17 00:00:00 2001 From: mischa Date: Tue, 6 Feb 2024 18:06:26 +0100 Subject: [PATCH] PredictedRigidbody: add OnBeforeApplyState callback --- .../Components/PredictedRigidbody/PredictedRigidbody.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs b/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs index 952b18882..c16805df3 100644 --- a/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs +++ b/Assets/Mirror/Components/PredictedRigidbody/PredictedRigidbody.cs @@ -431,6 +431,7 @@ void RecordState() // optional user callbacks, in case people need to know about events. protected virtual void OnSnappedIntoPlace() {} + protected virtual void OnBeforeApplyState() {} protected virtual void OnCorrected() {} void ApplyState(double timestamp, Vector3 position, Quaternion rotation, Vector3 velocity) @@ -468,6 +469,11 @@ void ApplyState(double timestamp, Vector3 position, Quaternion rotation, Vector3 return; } + // we have a callback for snapping into place (above). + // we also need one for corrections without snapping into place. + // call it before applying pos/rot/vel in case we need to set kinematic etc. + OnBeforeApplyState(); + // Rigidbody .position teleports, while .MovePosition interpolates // TODO is this a good idea? what about next capture while it's interpolating? if (correctionMode == CorrectionMode.Move)