Drag and drop gameobject on terrain

Hi,
I am really struggling here and I need some help with drag and drop gameobject on terrain. I wrote the following code but it gives me a strange result. When i drop my object, it actually bounces from terrain as ball.

void OnMouseDrag () {

Ray ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit = new RaycastHit();

if(Physics.Raycast(ray,out hit))
{

//We’ve hit something

if(hit.collider.gameObject.name.Equals(“Terrain”)) {
transform.position = hit.point;
}
}
}

What is the best way to do drag and drop gameobject on terrain? I would like to keep game object position where I click my mouse.

Thank you for your help !!!

Your object is bouncing because you are actually placing it inside the terrain when you click. You’re putting the center of your object at the point of collision, which is right on the terrain. You want to use the hit point but then add 1/2 the height of the gameobject to the position.y value

THANKS!!!

refer to this blog.
Layer masks were used here.