when the distance between the origin of the raycast and the collider that was hit is greater than 1, the raycast works correctly, but as soon as the distance is less than equal 1, then the raycast goes through the collider and doesnt hit it.
and here is the code
//draw a path in the direction of the velocity.
RaycastHit2D rayHit = Physics2D.Raycast (new Vector2 (transform.position.x + velocityDirection.x,
transform.position.y + velocityDirection.y),
new Vector2 (velocityDirection.x, velocityDirection.y));
if (rayHit!=null) {
path.SetVertexCount (2);
path.SetPosition (0, new Vector3 (transform.position.x + velocityDirection.x * 0.1f,
transform.position.y + velocityDirection.y * 0.1f,
Camera.main.farClipPlane));
path.SetPosition (1, new Vector3 (rayHit.point.x,
rayHit.point.y,
Camera.main.farClipPlane));