Ejemplo n.º 1
0
    public static Collider2D ComputeHorizontalRaycast(Vector2 origin, Collider2D refCollider, int objectLayer, bool drawDebug, float debugDuration, Color color)
    {
        origin.y -= refCollider.bounds.size.y * 0.55f - refCollider.offset.y;
        origin.x -= refCollider.bounds.size.x * 0.3f;
        float distance = refCollider.bounds.size.x * 0.8f;

        int layer = CollisionMatrixLayerMasks.MaskForLayer(objectLayer);

        if (drawDebug)
        {
            Debug.DrawRay(origin, Vector3.right * distance, color, debugDuration);
        }

        RaycastHit2D hitInfos = Physics2DUtility.RaycastAllWithEffector(origin, Vector2.right, distance, layer, drawDebug);

        return(hitInfos ? hitInfos.collider : null);
    }
Ejemplo n.º 2
0
    public static Collider2D ComputeVerticalRayWithEffector(Vector2 origin, Collider2D refCollider, float forward, int objectLayer, bool drawDebug = false, float debugDuration = 0f)
    {
        float distance = refCollider.bounds.size.y * 0.75f;

        origin.x += forward * refCollider.bounds.size.x * 0.55f + (forward * 0.1f);
        origin.y += refCollider.bounds.size.y * 0.4f + refCollider.offset.y;

        int layer = CollisionMatrixLayerMasks.MaskForLayer(objectLayer);

        if (drawDebug)
        {
            Debug.DrawRay(origin, Vector3.down * distance, Color.red, debugDuration);
        }

        RaycastHit2D hitInfos = Physics2DUtility.RaycastAllWithEffector(origin, Vector2.down, distance, layer, drawDebug);

        return(hitInfos ? hitInfos.collider : null);
    }