private static void UpdateSupport(WearNTear wear) { if (wear.m_colliders == null) { wear.SetupColliders(); } var materialProperties = materialLookup[wear.m_materialType]; Vector3 cOM = wear.GetCOM(); float maxSupport = 0f; foreach (WearNTear.BoundData bound in wear.m_bounds) { int numColliders = Physics.OverlapBoxNonAlloc(bound.m_pos, bound.m_size, tempColliders, bound.m_rot, WearNTear.m_rayMask); for (int i = 0; i < numColliders; i++) { Collider collider = tempColliders[i]; if (wear.m_colliders.Contains(collider) || collider.attachedRigidbody != null || collider.isTrigger) { continue; } WearNTear touchingWear = collider.GetComponentInParent <WearNTear>(); if (touchingWear == null) { wear.m_support = materialProperties.maxSupport; return; } if (!touchingWear.m_supports) { continue; } float distanceToTouching = Vector3.Distance(cOM, touchingWear.transform.position) + 0.1f; float support = touchingWear.m_support; maxSupport = Mathf.Max(maxSupport, support - materialProperties.horizontalLoss * distanceToTouching * support); Vector3 vector = wear.FindSupportPoint(cOM, touchingWear, collider); if (vector.y < cOM.y + 0.05f) { Vector3 normalized = (vector - cOM).normalized; if (normalized.y < 0f) { float angle = Mathf.Acos(1f - Mathf.Abs(normalized.y)) / ((float)Math.PI / 2f); float loss = Mathf.Lerp(materialProperties.horizontalLoss, materialProperties.verticalLoss, angle); float angledSupport = support - loss * distanceToTouching * support; maxSupport = Mathf.Max(maxSupport, angledSupport); } } } } wear.m_support = Mathf.Min(maxSupport, materialProperties.maxSupport); }