From 3850756a5b5fc65fd0faa1ae62be92bd7ea3abea Mon Sep 17 00:00:00 2001 From: mischa Date: Wed, 20 Mar 2024 21:31:07 +0800 Subject: [PATCH] Predicted Billiards: fix Rigidbody access for latest prediction --- .../Examples/BilliardsPredicted/Player/PlayerPredicted.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Assets/Mirror/Examples/BilliardsPredicted/Player/PlayerPredicted.cs b/Assets/Mirror/Examples/BilliardsPredicted/Player/PlayerPredicted.cs index 62585a3fe..73edadeaf 100644 --- a/Assets/Mirror/Examples/BilliardsPredicted/Player/PlayerPredicted.cs +++ b/Assets/Mirror/Examples/BilliardsPredicted/Player/PlayerPredicted.cs @@ -45,12 +45,17 @@ void ApplyForceToWhite(Vector3 force) // https://docs.unity3d.com/2021.3/Documentation/ScriptReference/Rigidbody.AddForce.html // this is buffered until the next FixedUpdate. + // get the white ball's Rigidbody. + // prediction sometimes moves this out of the object for a while, + // so we need to grab it this way: + Rigidbody rb = whiteBall.GetComponent().predictedRigidbody; + // AddForce has different force modes, see this excellent diagram: // https://www.reddit.com/r/Unity3D/comments/psukm1/know_the_difference_between_forcemodes_a_little/ // for prediction it's extremely important(!) to apply the correct mode: // 'Force' makes server & client drift significantly here // 'Impulse' is correct usage with significantly less drift - whiteBall.GetComponent().AddForce(force, ForceMode.Impulse); + rb.AddForce(force, ForceMode.Impulse); } // called when the local player dragged the white ball.