Esempio n. 1
0
    /*WORKING*/
    public static HullCollision2D detectCollisionResponse(CircleHull2D circle, AABBHull2D square)
    {
        float   dist = Vector2.Distance(circle.position, square.GetClosestPoint(circle.position));
        Vector2 squareClosestPoint = square.GetClosestPoint(circle.position);
        Vector2 circleClosestPoint = circle.GetClosestPoint(squareClosestPoint); //need to do second

        Debug.DrawLine(squareClosestPoint, circleClosestPoint);
        if (circle.radius > dist)
        {
            Vector2 pen     = squareClosestPoint - circleClosestPoint;
            Vector2 penNorm = pen.normalized;
            if (penNorm.x > penNorm.y)
            {
                pen.y = 0.0f;
            }
            else
            {
                pen.x = 0.0f;
            }
            HullCollision2D collision;
            collision = new HullCollision2D(circle, square, penNorm.normalized, pen.magnitude);
            return(collision);
        }
        return(null);
    }
Esempio n. 2
0
    //TODO
    public static HullCollision2D detectCollisionResponse(CircleHull2D circle, OBBHull2D square)
    {
        Vector2 closestPointSquare = square.GetClosestPoint(circle.position);
        Vector2 closestPointCircle = circle.GetClosestPoint(closestPointSquare);

        Debug.DrawLine(new Vector3(closestPointSquare.x, closestPointSquare.y, 0), new Vector3(closestPointCircle.x, closestPointCircle.y, 0));
        if (circle.radius > Vector2.Distance(circle.position, closestPointSquare))
        {
            Vector2         penNorm = closestPointSquare - closestPointCircle;
            HullCollision2D collision;
            if (penNorm.x > 0.0f)
            {
                collision = new HullCollision2D(circle, square, penNorm.normalized, penNorm.magnitude);
            }
            else
            {
                collision = new HullCollision2D(circle, square, penNorm.normalized, penNorm.magnitude);
            }
            return(collision);
        }
        return(null);
    }