コード例 #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cap"></param>
 /// <param name="cir"></param>
 /// <returns></returns>
 public static bool CapsuleIntersectCircle(BoundsCapsule cap, BoundsCircle cir)
 {
     if (CircleIntersectCircle(cap.bottomCircleBounds, cir))
     {
         return(true);
     }
     if (CircleIntersectCircle(cap.topCircleBounds, cir))
     {
         return(true);
     }
     if (RectIntersectCircle(cap.rectBounds, cir))
     {
         return(true);
     }
     return(false);
 }
コード例 #2
0
 /// <summary>
 /// Returns true if the line passes through the given capsule
 /// </summary>
 /// <param name="bounds"></param>
 /// <param name="origin"></param>
 /// <param name="direction"></param>
 /// <param name="length"></param>
 /// <returns></returns>
 public static bool LineIntersectsCapsule(BoundsCapsule bounds, Vector2 origin, Vector2 direction, float length)
 {
     if (LineIntersectCircle(bounds.topCircleBounds, origin, direction, length))
     {
         return(true);
     }
     if (LineIntersectCircle(bounds.bottomCircleBounds, origin, direction, length))
     {
         return(true);
     }
     if (LineIntersectRect(bounds.rectBounds, origin, direction, length))
     {
         return(true);
     }
     return(false);
 }
コード例 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="capsuleBounds"></param>
 /// <param name="colliderToCheck"></param>
 /// <returns></returns>
 private bool CheckColliderIntersectFromBounds(BoundsCapsule capsuleBounds, CustomCollider2D colliderToCheck)
 {
     if (colliderToCheck is CustomBoxCollider2D)
     {
         return(CapsuleIntersectRect(capsuleBounds, ((CustomBoxCollider2D)colliderToCheck).bounds));
     }
     else if (colliderToCheck is CustomCircleCollider2D)
     {
         return(CapsuleIntersectCircle(capsuleBounds, ((CustomCircleCollider2D)colliderToCheck).bounds));
     }
     else if (colliderToCheck is CustomCapsuleCollider2D)
     {
         return(CapsuleIntersectCapsule(capsuleBounds, ((CustomCapsuleCollider2D)colliderToCheck).bounds));
     }
     return(false);
 }
コード例 #4
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="c"></param>
    /// <param name="r"></param>
    /// <returns></returns>
    public static bool CapsuleIntersectRect(BoundsCapsule c, BoundsRect r)
    {
        if (RectIntersectCircle(r, c.bottomCircleBounds))
        {
            return(true);
        }
        if (RectIntersectCircle(r, c.bottomCircleBounds))
        {
            return(true);
        }
        if (RectIntersectRect(r, c.rectBounds))
        {
            return(true);
        }

        return(false);
    }
コード例 #5
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="c"></param>
    /// <param name="r"></param>
    /// <returns></returns>
    public static bool CapsuleIntersectCapsule(BoundsCapsule c, BoundsCapsule r)
    {
        if (CapsuleIntersectRect(c, r.rectBounds))
        {
            return(true);
        }
        if (CapsuleIntersectCircle(c, r.topCircleBounds))
        {
            return(true);
        }
        if (CapsuleIntersectCircle(c, r.bottomCircleBounds))
        {
            return(true);
        }

        return(false);
    }
コード例 #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="boundsToCheck"></param>
 /// <param name="colliderToCheck"></param>
 /// <returns></returns>
 private bool ColliderIntersectBounds(BoundsCapsule boundsToCheck, CustomCollider2D colliderToCheck)
 {
     if (colliderToCheck is CustomBoxCollider2D)
     {
         return(CapsuleIntersectRect(boundsToCheck, ((CustomBoxCollider2D)colliderToCheck).bounds));
     }
     else if (colliderToCheck is CustomCircleCollider2D)
     {
         return(CapsuleIntersectCircle(boundsToCheck, ((CustomCircleCollider2D)colliderToCheck).bounds));
     }
     else if (colliderToCheck is CustomCapsuleCollider2D)
     {
         return(CapsuleIntersectCapsule(((CustomCapsuleCollider2D)colliderToCheck).bounds, boundsToCheck));
     }
     else
     {
         return(false);
     }
 }
コード例 #7
0
    /// <summary>
    /// Updates the bounds of the capsule collider. The Capsule collider is made up of one rect bounds and two circle bounds
    /// </summary>
    public override void UpdateBoundsOfCollider()
    {
        BoundsRect b      = new BoundsRect();
        Vector2    origin = this.transform.position + new Vector3(colliderOffset.x, colliderOffset.y);
        float      xSize  = drawHorizontal ? size : radius * 2;
        float      ySize  = drawHorizontal ? radius * 2 : size;


        b.topLeft         = origin + Vector2.up * ySize / 2 - Vector2.right * xSize / 2;
        b.topRight        = origin + Vector2.up * ySize / 2 + Vector2.right * xSize / 2;
        b.bottomLeft      = origin - Vector2.up * ySize / 2 - Vector2.right * xSize / 2;
        b.bottomRight     = origin - Vector2.up * ySize / 2 + Vector2.right * xSize / 2;
        bounds.rectBounds = b;

        BoundsCircle topCircle = new BoundsCircle();

        topCircle.center       = b.topLeft + (b.topRight - b.topLeft) / 2f;
        topCircle.radius       = radius;
        bounds.topCircleBounds = topCircle;

        BoundsCircle bottomCircle = new BoundsCircle();

        bottomCircle.center       = b.bottomLeft + (b.bottomRight - b.bottomLeft) / 2f;
        bottomCircle.radius       = radius;
        bounds.bottomCircleBounds = bottomCircle;

        if (!isStatic)
        {
            verticalBounds = bounds;

            verticalBounds.topCircleBounds.radius    = bounds.topCircleBounds.radius - colliderBuffer;
            verticalBounds.bottomCircleBounds.radius = bounds.bottomCircleBounds.radius - colliderBuffer;
            verticalBounds.rectBounds.topLeft.x      = bounds.rectBounds.topLeft.x + colliderBuffer / 2;
            verticalBounds.rectBounds.topRight.x     = bounds.rectBounds.topRight.x - colliderBuffer / 2;
            verticalBounds.rectBounds.bottomLeft.x   = verticalBounds.rectBounds.topLeft.x;
            verticalBounds.rectBounds.bottomRight.x  = verticalBounds.rectBounds.topRight.x;



            horizontalBounds = bounds;
            horizontalBounds.topCircleBounds.radius    -= colliderBuffer;
            horizontalBounds.bottomCircleBounds.radius -= colliderBuffer;

            //horizontalBounds.topCircleBounds.center += Vector2.down * colliderBuffer;
            //horizontalBounds.bottomCircleBounds.center += Vector2.up * colliderBuffer;

            Vector2 horizontalOffset = Vector2.zero;
            Vector2 verticalOffset   = Vector2.zero;

            if (rigid.Velocity.y > 0)
            {
                verticalOffset = Vector2.up * Mathf.Max(colliderBuffer, rigid.Velocity.y * Overseer.DELTA_TIME);
            }
            else if (rigid.Velocity.y < 0)
            {
                verticalOffset = Vector2.up * Mathf.Min(-colliderBuffer, rigid.Velocity.y * Overseer.DELTA_TIME);
            }

            if (rigid.Velocity.x > 0)
            {
                horizontalOffset = Vector2.right * Mathf.Max(colliderBuffer, rigid.Velocity.x * Overseer.DELTA_TIME);
            }
            else if (rigid.Velocity.x < 0)
            {
                horizontalOffset = Vector2.right * Mathf.Min(-colliderBuffer, rigid.Velocity.x * Overseer.DELTA_TIME);
            }


            verticalBounds.SetOffset(verticalOffset);
            horizontalBounds.SetOffset(horizontalOffset);
        }
    }