예제 #1
0
        // Update is called once per frame
        void Update()
        {
            Vector3         trp    = transform.position;
            CollisionResult cr     = new CollisionResult();
            var             hitbox = target !.Hitbox;

            if (debug == DebugColliderType.AABB)
            {
                cr = new CollisionResult(false,
                                         CollisionMath.CircleOnAABB(
                                             new AABB(trp, new Vector2(rectHalfX, rectHalfY))
                                             , target.location, target.largeRadius));
            }
            else if (debug == DebugColliderType.WeakAABB)
            {
                cr = new CollisionResult(false,
                                         CollisionMath.WeakCircleOnAABB(-rectHalfX, -rectHalfY, rectHalfX, rectHalfY,
                                                                        target.location.x - trp.x, target.location.y - trp.y, target.largeRadius));
            }
            else if (colliderType == ColliderType.Circle)
            {
                cr = CollisionMath.GrazeCircleOnCircle(hitbox, trp, radius * scale);
            }
            else if (colliderType == ColliderType.Line)
            {
                float maxdist = Mathf.Max(point2.magnitude, point1.magnitude) + radius;
                cr = CollisionMath.GrazeCircleOnRotatedSegment(hitbox, trp, radius,
                                                               point1, point2 - point1, scale, (point2 - point1).sqrMagnitude, maxdist * maxdist,
                                                               Mathf.Cos(rotationDeg * Mathf.PI / 180f), Mathf.Sin(rotationDeg * Mathf.PI / 180f));
            }
            else if (colliderType == ColliderType.Rectangle)
            {
                cr = CollisionMath.GrazeCircleOnRect(hitbox, trp, rectHalfX, rectHalfY, rectHalfX * rectHalfX + rectHalfY * rectHalfY, scale,
                                                     Mathf.Cos(rotationDeg * Mathf.PI / 180f), Mathf.Sin(rotationDeg * Mathf.PI / 180f));
            }
            else if (colliderType == ColliderType.RectPtColl)
            {
                cr = new CollisionResult(CollisionMath.PointInRect(target.location, new CRect(
                                                                       trp.x, trp.y,
                                                                       rectHalfX, rectHalfY, rotationDeg
                                                                       )), false);
            }
            else if (colliderType == ColliderType.Segments)
            {
                cr = CollisionMath.GrazeCircleOnSegments(hitbox, transform.position, points, start, skip, end, radius,
                                                         Mathf.Cos(rotationDeg * Mathf.PI / 180f), Mathf.Sin(rotationDeg * Mathf.PI / 180f));
            }
            if (cr.graze)
            {
                Debug.Break();
            }
        }