From d5613321bf4d7ae5c44b97538f8ea9f0769084af Mon Sep 17 00:00:00 2001 From: mischa Date: Wed, 3 Apr 2024 19:18:55 +0800 Subject: [PATCH] fix impulse dir --- .../Components/ForecastRigidbody/ForecastRigidbody.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Assets/Mirror/Components/ForecastRigidbody/ForecastRigidbody.cs b/Assets/Mirror/Components/ForecastRigidbody/ForecastRigidbody.cs index 3dc8a590d..03c94d2d1 100644 --- a/Assets/Mirror/Components/ForecastRigidbody/ForecastRigidbody.cs +++ b/Assets/Mirror/Components/ForecastRigidbody/ForecastRigidbody.cs @@ -321,7 +321,11 @@ void OnCollisionEnter(Collision collision) // the other object is in FOLLOWING mode (kinematic). // PhysX will register the collision, but not add the collision force while kinematic. // we need to add the force manually, which will also begin predicting it. - other.AddPredictedForce(-collision.impulse, ForceMode.Impulse); + // => collision.impulse is sometimes from A->B and sometimes B->A. + // => we need to calculate the direction manually to always be A->B. + Vector3 direction = other.transform.position - transform.position; + Vector3 impulse = direction.normalized * collision.impulse.magnitude; + other.AddPredictedForce(impulse, ForceMode.Impulse); } // optional user callbacks, in case people need to know about events.