Raycast sometimes ignore objects.

Hello,
I have a problem with Raycast, when sometimes ignore object which they are between two points.
I using this script:

 if (Physics.Raycast (transform.position, Vector3(x2,0.5,z2),hit,Mathf.Infinity)){
    //Do something
    }

Sometimes it works but if I rotate a object between those points, it stop working and ignore it. Sometimes raycast detect collision when is closer to object.
For example and better imagination there is two pictures:

At first one is collision detected right, because there are colored lines. Object in the middle is object on our way. The smaller one at right is moving to the point at left.

15108-example1.jpg

On the second is object on a way but raycast not detected collision.
15109-example2.jpg

So I need a help whats wrong is with raycast. Maybe I using it a bad way. Thank you for help. Sorry for my English.

Take a look better look in documentation and double check your code and variables. Especially, what is each param.

static function Raycast(origin: Vector3, direction: Vector3, hitInfo: RaycastHit): bool;

The raycast function expected a direction and you are giving a point.

Change the

Vector3(x2,0.5,z2)

to

(Vector3(x2,0.5,z2) - transform.position).normalized