RaycastHit behind object

How I should get raycastHit behind rigidbody? Box on this picture has rigidbody, but raycast should get “hit.point” from the wall, not box.

Sorry only time for a very quick comment.

This can be done using LayerMask.

In the Inspector, click the dropdown box next to the variable myLayerMask. Tick to select the layers in which you want the raycast to work. Your colliders need to have their layers set to whatever you want. If you have everything on the same layer this will notwork.

// JavaScript example.

var myLayerMask : LayerMask;

function Update() 
{
	var hit : RaycastHit;

	// Does the ray intersect any objects excluding the myLayerMask layer
	if ( Physics.Raycast( transform.position, transform.forward, hit, Mathf.Infinity, myLayerMask ) ) 
	{
		Debug.DrawRay( transform.position, transform.forward * hit.distance, Color.yellow );
		Debug.Log( "Did Hit " + hit.collider.gameObject.name );
	}
	else 
	{
		Debug.DrawRay (transform.position, transform.TransformDirection (Vector3.forward) *1000, Color.white);
		Debug.Log( "Did not Hit" );
	}
}

If you put the box in the ignoreraycast layer, the raycasts will ignore the box completely and go right through it.