From b0709dbd813f8be3470b176f64baea47e0a3e80e Mon Sep 17 00:00:00 2001 From: Gregory Labute Date: Tue, 18 Jun 2024 08:26:12 -0400 Subject: [PATCH] Bugfix: RuntimeUtility.SphereCastIgnoreTag was sometimes retruning NaN result. --- com.unity.cinemachine/CHANGELOG.md | 1 + com.unity.cinemachine/Runtime/Core/RuntimeUtility.cs | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/com.unity.cinemachine/CHANGELOG.md b/com.unity.cinemachine/CHANGELOG.md index a30fcb56b..b40a0fb26 100644 --- a/com.unity.cinemachine/CHANGELOG.md +++ b/com.unity.cinemachine/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Bugfix: The GroupAverage Rotation Mode in CinemachineTargetGroup was not calculated properly. - Bugfix: PostProcessing and VolumeSettings were not blending correctly to and from empty profiles. - Bugfix: added missing null check in CinemachineTargetGroup.WeightedMemberBoundsForValidMember. +- Bugfix: RuntimeUtility.SphereCastIgnoreTag was sometimes retruning NaN result. ## [2.10.0] - 2024-01-01 diff --git a/com.unity.cinemachine/Runtime/Core/RuntimeUtility.cs b/com.unity.cinemachine/Runtime/Core/RuntimeUtility.cs index 8cf7ce68d..b9ab6009d 100644 --- a/com.unity.cinemachine/Runtime/Core/RuntimeUtility.cs +++ b/com.unity.cinemachine/Runtime/Core/RuntimeUtility.cs @@ -127,9 +127,6 @@ public static bool SphereCastIgnoreTag( // Collect overlapping items if (h.distance == 0 && h.normal == -dir) { - if (s_PenetrationIndexBuffer.Length > numPenetrations + 1) - s_PenetrationIndexBuffer[numPenetrations++] = i; - // hitInfo for overlapping colliders will have special // values that are not helpful to the caller. Fix that here. var scratchCollider = GetScratchCollider(); @@ -145,7 +142,12 @@ public static bool SphereCastIgnoreTag( h.distance = offsetDistance - radius; // will be -ve h.normal = offsetDir; s_HitBuffer[i] = h; - penetrationDistanceSum += h.distance; + if (h.distance < -0.0001f) + { + penetrationDistanceSum += h.distance; + if (s_PenetrationIndexBuffer.Length > numPenetrations + 1) + s_PenetrationIndexBuffer[numPenetrations++] = i; + } } else {