Raycast moved object won't go under certain height

Hi, i’m trying to move an object based on raycast over the terrain. So it’s the typical thing.
It works fine, the object moves along the mouse, over the terrain detecting the hit. The problem is it only works over mountains. I have no idea why, when I mouse over the plains and low altitude parts of the terrain, the object gets stuck on the mountain and don’t come down.
Then if I shift the mouse from mountain to mountain the object just teleport there, without going through the plains with the mouse.
It’s like it has a height limit, but nowhere I code that. Here the code:

using UnityEngine;
using System.Collections;

public class FollowMouseOnTerrain : MonoBehaviour {

	public Camera cameraToFollow;				//player cam
	public GameObject controllerObject;			//controller object
	public Terrain terrain;						//terrain
	
	private Ray _ray;							//ray
	private RaycastHit _hit;					//hit
		
	
	void Update () {
	
		_ray = cameraToFollow.camera.ScreenPointToRay(Input.mousePosition);
		
		Debug.DrawRay(_ray.origin, _ray.direction * 10, Color.yellow);		//works fine
			
		if(Physics.Raycast(_ray.origin, _ray.direction * 10, out _hit)){		//raycast
			
			if(_hit.collider == terrain.collider){
				
				controllerObject.transform.position = _hit.point;
				
			}
			
		}
			
	}
}

This code should work. Looks like you have a kind of invisible plane that’s blocking the raycast before it hits the lower parts of the terrain. You could change the inner if like this:

       ...
       if(Physics.Raycast(_ray.origin, _ray.direction * 10, out _hit)){   //raycast
         if(_hit.collider != controllerObject.collider){
           controllerObject.transform.position = _hit.point;
         }
       }
       ...

This could help understanding what’s actually happening.

NOTE: You could use only Physics.Raycast(ray, out hit) - it’s a little faster, since there are less parameters to pass.

For a test, print out what/when it hits to something you can see in the Inspector. Maybe it’s hitting something that blocks it, or missing(?) somehow:

public string hName; // debugging global variable

...
if( raycast ) { hName=_hit.transform.name;
   ...
} else hName="<missed>";

AAAAAAAAAA I just found out what it was. Super dumb thing. I forgot that the outer perimeter of the map had the collider on, and it’s a bit over the play map.

Works nice now perfect. Thanks for help!