public static bool SphereBoxCollisionOccured(PSI_Collider_Sphere sphereCol, PSI_Collider_Box boxCol, out Vector3 point) { // Get the closest point on the surface of the box to the sphere. point = boxCol.GetClosestPointOnBox(sphereCol.pPosition); // Do a distance check to see if the sphere and box are colliding. var collisionVector = point - sphereCol.pPosition; bool isColliding = collisionVector.magnitude <= Mathf.Abs(sphereCol.pRadius); if (isColliding) { // Resolve any overlap between the sphere and the box. var collisionAxis = CorrectCollisionAxisDirection(boxCol.pPosition, sphereCol.pPosition, collisionVector); float overlap = collisionVector.magnitude - sphereCol.pRadius; ResolveCollisionOverlaps(sphereCol, boxCol, collisionAxis, overlap); // Calculate and apply the collision impulse to the sphere and the box. ApplyImpulses(sphereCol, boxCol, collisionAxis, point); return(true); } return(false); }