raycast2D not working.

I’m making a AI to follow the player, but if the AI is near a pit, it will stop. i’m using raycast2D, and a if statement:

** RaycastHit2D hitLeft = Physics2D.Raycast(leftEdge.transform.position, Vector2.down, 0.6f);
RaycastHit2D hitRight = Physics2D.Raycast(rightEdge.transform.position, Vector2.down, 0.6f);

    if (hitLeft.collider == null)
    {
        speed = 0f;
        Debug.Log("Left's not working");
    }

    if (hitRight.collider == null)
    {
        speed = 0f;
        Debug.Log("Right's not woking");
    } **

but it doesn’t matter if the collider is null or not, it will always change the speed to 0 and do both debug.logs.

(sorry for my bad English btw)

never mind. already fixed it

` RaycastHit2D hitLeft = Physics2D.Raycast(leftEdge.transform.position, Vector2.down);
RaycastHit2D hitRight = Physics2D.Raycast(rightEdge.transform.position, Vector2.down);

    if (hitLeft.collider != false)
    {
        mainBody.position = Vector2.MoveTowards(mainBody.position, new Vector2(target.position.x, transform.position.y), speed * Time.deltaTime);
    } else
    {
        mainBody.position = Vector2.MoveTowards(mainBody.position, new Vector2(-target.position.x, transform.position.y), speed * Time.deltaTime);
    }

    if (hitRight.collider != false)
    {
        mainBody.position = Vector2.MoveTowards(mainBody.position, new Vector2(target.position.x, transform.position.y), speed * Time.deltaTime);
    } else
    {
        mainBody.position = Vector2.MoveTowards(mainBody.position, new Vector2(-target.position.x, transform.position.y), speed * Time.deltaTime);
    }`.