From cb8f91cc5462ed95fce00feaf6c851cc08d6d462 Mon Sep 17 00:00:00 2001 From: Jeremy Schiff Date: Mon, 21 Apr 2025 13:10:39 -0400 Subject: [PATCH 1/3] Fix no sleeping --- Assets/BetterPhysics/Runtime/Scripts/BetterRigidbody.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/BetterPhysics/Runtime/Scripts/BetterRigidbody.cs b/Assets/BetterPhysics/Runtime/Scripts/BetterRigidbody.cs index 46fd663..1ab2538 100644 --- a/Assets/BetterPhysics/Runtime/Scripts/BetterRigidbody.cs +++ b/Assets/BetterPhysics/Runtime/Scripts/BetterRigidbody.cs @@ -57,11 +57,11 @@ public void SetLimit(int index, SpeedLimit limit) { public int LimitCount => limits.Count; private void FixedUpdate() { - if (!_rb.isKinematic) { + if (!_rb.isKinematic && _exemptedVelocityChange != Vector3.zero) { // Apply exempted newtons directly to the velocity _rb.AddLinearVelocity(_exemptedVelocityChange); + _exemptedVelocityChange = Vector3.zero; } - _exemptedVelocityChange = Vector3.zero; ApplyLimits(); } @@ -838,4 +838,4 @@ private Vector3 CalculateVelocityChangeWithSoftLimit(in Vector3 currentVelocity, #endregion } -} \ No newline at end of file +} From 05c569b82cfa6057dd1beeb4d522d82439e58ad7 Mon Sep 17 00:00:00 2001 From: Jeremy Schiff Date: Mon, 21 Apr 2025 13:29:09 -0400 Subject: [PATCH 2/3] More checks for no-ops --- Assets/BetterPhysics/Runtime/Scripts/BetterRigidbody.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Assets/BetterPhysics/Runtime/Scripts/BetterRigidbody.cs b/Assets/BetterPhysics/Runtime/Scripts/BetterRigidbody.cs index 1ab2538..3073ac5 100644 --- a/Assets/BetterPhysics/Runtime/Scripts/BetterRigidbody.cs +++ b/Assets/BetterPhysics/Runtime/Scripts/BetterRigidbody.cs @@ -176,7 +176,8 @@ private void ApplyHardLimit(SpeedLimit limit) { switch (limit.Directionality) { case Directionality.Omnidirectional: Vector3 clampedVelocity = Vector3.ClampMagnitude(expectedNewVelocity, limit.ScalarLimit); - + + if (currentVelocity == clampedVelocity && accumulatedNewtowns == 0) return; // We're hard clamping so remove all accumulated force _rb.AddForce(-accumulatedNewtons); _rb.SetLinearVelocity(clampedVelocity); @@ -193,6 +194,8 @@ private void ApplyHardLimit(SpeedLimit limit) { clampedNewVelocity[i] = Mathf.Clamp(clampedNewVelocity[i], -max[i], max[i]); } } + + if (currentVelocity == clampedVelocity && accumulatedNewtowns == 0) return; // We're hard clamping so remove all accumulated force _rb.AddForce(-accumulatedNewtons); @@ -216,6 +219,8 @@ private void ApplyHardLimit(SpeedLimit limit) { Vector3 clampedWorldVelocity = _rb.rotation * clampedLocalVelocity; + if (currentVelocity == clampedWorldVelocity && accumulatedNewtowns == 0) return; + // We're hard clamping so remove all accumulated force _rb.AddForce(-accumulatedNewtons); _rb.SetLinearVelocity(clampedWorldVelocity); From 57eb8a79a8b6f84d1a687cd151a90e2a257a8ac8 Mon Sep 17 00:00:00 2001 From: Jeremy Schiff Date: Mon, 21 Apr 2025 13:47:20 -0400 Subject: [PATCH 3/3] Fix typo. Newtowns -> Newtons --- Assets/BetterPhysics/Runtime/Scripts/BetterRigidbody.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/BetterPhysics/Runtime/Scripts/BetterRigidbody.cs b/Assets/BetterPhysics/Runtime/Scripts/BetterRigidbody.cs index 3073ac5..17e21c6 100644 --- a/Assets/BetterPhysics/Runtime/Scripts/BetterRigidbody.cs +++ b/Assets/BetterPhysics/Runtime/Scripts/BetterRigidbody.cs @@ -177,7 +177,7 @@ private void ApplyHardLimit(SpeedLimit limit) { case Directionality.Omnidirectional: Vector3 clampedVelocity = Vector3.ClampMagnitude(expectedNewVelocity, limit.ScalarLimit); - if (currentVelocity == clampedVelocity && accumulatedNewtowns == 0) return; + if (currentVelocity == clampedVelocity && accumulatedNewtons == 0) return; // We're hard clamping so remove all accumulated force _rb.AddForce(-accumulatedNewtons); _rb.SetLinearVelocity(clampedVelocity); @@ -195,7 +195,7 @@ private void ApplyHardLimit(SpeedLimit limit) { } } - if (currentVelocity == clampedVelocity && accumulatedNewtowns == 0) return; + if (currentVelocity == clampedVelocity && accumulatedNewtons == 0) return; // We're hard clamping so remove all accumulated force _rb.AddForce(-accumulatedNewtons); @@ -219,7 +219,7 @@ private void ApplyHardLimit(SpeedLimit limit) { Vector3 clampedWorldVelocity = _rb.rotation * clampedLocalVelocity; - if (currentVelocity == clampedWorldVelocity && accumulatedNewtowns == 0) return; + if (currentVelocity == clampedWorldVelocity && accumulatedNewtons == 0) return; // We're hard clamping so remove all accumulated force _rb.AddForce(-accumulatedNewtons);