/// <summary> /// Performs collision detection and response on a sphere and plane. /// </summary> public void SphereOnPlane(SphereCollider lhs, PlaneCollider rhs) { // We need position of each object and the normal of the plane. var sphere = lhs.position; var plane = rhs.position; var normal = rhs.transform.up; // The formula for collision is: c.n - q.n < radium. var sphereDot = Vector3.Dot(sphere, normal); var planeDot = Vector3.Dot(plane, normal); var distance = sphereDot - planeDot; if (distance < lhs.radius) { // We've collided! var intersection = lhs.radius - distance; var pointOfContact = sphere - normal * intersection; response.Respond(lhs, rhs, -normal, intersection, pointOfContact); } else { response.NotColliding(lhs, rhs); } }
/// <summary> /// Performs collision detection between a plane and sphere. /// </summary> public void PlaneOnSphere(PlaneCollider lhs, SphereCollider rhs) { SphereOnPlane(rhs, lhs); }
public void PlaneOnPlane(PlaneCollider lhs, PlaneCollider rhs) { // TODO: Implement plane on plane. }