public bool CheckForIntersection(OOB_Objects oobOther) { Vector3[] SeparateAxis = new Vector3[15] { transform.forward, transform.right, transform.up, oobOther.transform.forward, oobOther.transform.right, oobOther.transform.up, Vector3.Cross(transform.forward, oobOther.transform.forward).normalized, Vector3.Cross(transform.forward, oobOther.transform.right).normalized, Vector3.Cross(transform.forward, oobOther.transform.up).normalized, Vector3.Cross(transform.right, oobOther.transform.forward).normalized, Vector3.Cross(transform.right, oobOther.transform.right).normalized, Vector3.Cross(transform.right, oobOther.transform.up).normalized, Vector3.Cross(transform.up, oobOther.transform.forward).normalized, Vector3.Cross(transform.up, oobOther.transform.right).normalized, Vector3.Cross(transform.up, oobOther.transform.up).normalized }; bool result = true; foreach (Vector3 axis in SeparateAxis) { result = result && IntersectsWhenProjected(Corners, oobOther.OrientedBounds.Corners, axis); if (!result) { return(false); } } return(result); }
// Update is called once per frame void Update() { if (show) { if (obbComponent != null) { // Draw default debug stuff (bounding box) DrawDebug(); // Draw Closest Point if (showClosestPoint) { DrawDebugClosestPoint(); } // Draw Intersection Info if (showIntersection && intersectionText != null && objectToCheckIntersectionAgainst != null) { intersectionText.rectTransform.position = transform.position; if (!intersectionText.gameObject.activeSelf) { intersectionText.gameObject.SetActive(true); } if (obbComponent.OrientedBounds.CheckForIntersection(objectToCheckIntersectionAgainst)) { intersectionText.color = colorIntersecting; intersectionText.text = "Intersecting"; } else { intersectionText.color = colorNotIntersecting; intersectionText.text = "Not Intersecting"; } } } else { obbComponent = GetComponent <OOB_Objects>(); } } }