RaycastHit2D has a offset or something

here’s my code:

    public void CheckRayCast()
        RaycastHit2D hit = Physics2D.Raycast(transform.position, target.position, 50f, ~layer_mask);

        Debug.DrawRay(transform.position, target.position, Color.green);

        if (hit)


This code was attached to the square.

I have been trying to detect the circle(target) using ray cast, so that the square only shoots when the circle is visible, when I raycast it looks like the ray cast is offsetted and never hits the meant target. if someone could help me it would be awesome.

You need to use the direction, not the position, if you want to use the position you can use Unity - Scripting API: Physics2D.Linecast if you want to use raycast get the direction by

Vector3 dir = target.position - transform.position;