Simple fix for Height Change blocked by deactivated colliders

Cheo

Active member
Hello, this issue is quite similar to these two :

https://www.opsive.com/forum/index....bility-blocked-by-deactivated-collider.10137/

https://www.opsive.com/forum/index....blocked-by-deactivated-collider-in-hand.9197/

Basically, stopping the Height Change ability can be prevented by deactivated colliders. A simple if statement in CanStopAbility checking whether the collider is active is enough to fix this :

C#:
            // The ability can't stop if there isn't enough room for the character to occupy their original height.
            var capsuleColliderCount = 0;
            for (int i = 0; i < m_CharacterLocomotion.ColliderCount; ++i)
            {
                if (m_CharacterLocomotion.Colliders[i].gameObject.activeSelf)
                {
                    // Determine if the collider would intersect any objects.
                    if (m_CharacterLocomotion.Colliders[i] is CapsuleCollider)
                    {
                        var capsuleCollider = m_CharacterLocomotion.Colliders[i] as CapsuleCollider;
                        var radiusMultiplier = MathUtility.ColliderScaleMultiplier(capsuleCollider);
                        Vector3 startEndCap, endEndCap;
                        MathUtility.CapsuleColliderEndCaps(m_CapsuleColliderHeight[capsuleColliderCount] * MathUtility.CapsuleColliderHeightMultiplier(capsuleCollider),
                                                                    (capsuleCollider.radius - m_CharacterLocomotion.ColliderSpacing) * radiusMultiplier, Vector3.Scale(m_StartColliderCenter[i], capsuleCollider.transform.lossyScale), MathUtility.CapsuleColliderDirection(capsuleCollider),
                                                                    m_Transform.TransformPoint(m_CapsuleColliderPosition[capsuleColliderCount]), MathUtility.TransformQuaternion(m_Transform.rotation, m_CapsuleColliderRotation[capsuleColliderCount]), out startEndCap, out endEndCap);
                        // If there is overlap then the ability can't stop.
                        if (Physics.OverlapCapsuleNonAlloc(startEndCap, endEndCap, (capsuleCollider.radius - m_CharacterLocomotion.ColliderSpacing * 2) * radiusMultiplier, m_OverlapColliders, m_CharacterLayerManager.SolidObjectLayers, QueryTriggerInteraction.Ignore) > 0)
                        {
                            keepActive = true;
                            break;
                        }
                        capsuleColliderCount++;
                    }
                    else if (m_CharacterLocomotion.Colliders[i] is SphereCollider)
                    {
                        var sphereCollider = m_CharacterLocomotion.Colliders[i] as SphereCollider;
                        // If there is overlap then the ability can't stop.
                        if (Physics.OverlapSphereNonAlloc(sphereCollider.transform.TransformPoint(m_StartColliderCenter[i]), (sphereCollider.radius - m_CharacterLocomotion.ColliderSpacing * 2) * MathUtility.ColliderScaleMultiplier(sphereCollider),
                                                                        m_OverlapColliders, m_CharacterLayerManager.SolidObjectLayers, QueryTriggerInteraction.Ignore) > 0)
                        {
                            keepActive = true;
                            break;
                        }
                    }
                    else
                    { // BoxCollider.
                        var boxCollider = m_CharacterLocomotion.Colliders[i] as BoxCollider;
                        // If there is overlap then the ability can't stop.
                        if (Physics.OverlapBoxNonAlloc(boxCollider.transform.TransformPoint(m_StartColliderCenter[i]), boxCollider.size / 2 * MathUtility.ColliderScaleMultiplier(boxCollider),
                                                                        m_OverlapColliders, boxCollider.transform.rotation, m_CharacterLayerManager.SolidObjectLayers, QueryTriggerInteraction.Ignore) > 0)
                        {
                            keepActive = true;
                            break;
                        }
                    }
                }
            }

Here is also a quick video as usual :


Hope this can be added for the next update and the Hang and Cover ability can receive a similar fix, we really shouldn't have to worry about deactivated colliders. Thanks in advance.
 
Oh wait, it seems I've made a rookie mistake ! Instead of using activeSelf, we should be using activeInHierarchy, otherwise colliders whose parents are deactivated but who still have the activation box ticked will interfere. This can especially happen with colliders of other character models.
 
Top