Пример #1
0
    protected bool CheckForGround(bool debug)
    {
        Vector2 cStart     = (Vector2)feet.transform.position + 0.5f * Vector2.up;
        Vector2 cDirection = Vector2.down;
        float   cRadius    = feet.GetWidth() / 2;
        float   cDistance  = 0.5f + (transform.position - feet.transform.position).magnitude + feet.GetWidth() / 2f;

        // Using circle cast because we don't want the characters jumping on tiny inconsistencies in colliders
        RaycastHit2D hit    = Physics2D.CircleCast(cStart, cRadius, cDirection, cDistance, groundLayer);
        var          didHit = hit.collider != null;

        // Visual for the colliders
        if (debug)
        {
            DebugDrawPhysics.DebugDrawCircleCast(cStart, cRadius, cDirection, cDistance,
                                                 didHit ? Color.red : Color.green);
        }
        return(didHit);
    }