public static bool DetectCollision(PhysicsCollider colliderA, PhysicsCollider colliderB, ref Contact contact)
        {
            var bodyA      = colliderA.GetComponent <PhysicsBody>();
            var bodyB      = colliderB.GetComponent <PhysicsBody>();
            var transformA = colliderA.transform;
            var transformB = colliderB.transform;

            switch (colliderA.Type)
            {
            case PhysicsCollider.ShapeType.Sphere:
                var sphereA = (SphereCollider)colliderA;
                switch (colliderB.Type)
                {
                case PhysicsCollider.ShapeType.Sphere:
                    var sphereB = (SphereCollider)colliderB;
                    return(SphereVsSphere(bodyA, transformA.position, sphereA.radius, bodyB, transformB.position, sphereB.radius, ref contact));

                case PhysicsCollider.ShapeType.Plane:
                    var planeB = (PlaneCollider)colliderB;
                    return(SphereVsPlane(bodyA, transformA.position, sphereA.radius, bodyB, transformB.position, planeB.Normal, ref contact));
                }
                break;

            case PhysicsCollider.ShapeType.Plane:
                var planeA = (PlaneCollider)colliderA;
                switch (colliderB.Type)
                {
                case PhysicsCollider.ShapeType.Sphere:
                    var sphereB = (SphereCollider)colliderB;
                    return(SphereVsPlane(bodyB, transformB.position, sphereB.radius, bodyA, transformA.position, planeA.Normal, ref contact));

                case PhysicsCollider.ShapeType.Plane:
                    // no plane-plane collision detection
                    return(false);
                }
                break;
            }

            return(false);
        }
 public ColliderPair(PhysicsCollider colliderA, PhysicsCollider colliderB)
 {
     ColliderA = colliderA;
     ColliderB = colliderB;
 }
Exemplo n.º 3
0
 public static void Unregister(PhysicsCollider collider)
 {
     s_colliders.Remove(collider);
 }
Exemplo n.º 4
0
 public static void Register(PhysicsCollider collider)
 {
     ValidateWorld();
     s_colliders.Add(collider);
 }