Terrain collider not following hills when raycasting

I am coding up a system to allow the player to place objects on the terrain at runtime. To find the position to place the object, I’m raycasting down from the object’s origin until I hit the ground (layer ‘ground’), which is the layer assigned to my terrain.

My problem is that when I place the object in a hilly area of the terrain, the raycast seems to be finding the bottom area of my terrain as if it were flat (as opposed to the highest point between the object and the terrain at the hill). It seems as though the terrain collider isn’t following hills, and is simply flat.

My player walks up hills properly though (via the CharacterController).

Is there something special about terrain colliders vs. mesh colliders that causes raycasting against the terrain collider to ignore deformations in the terrain?

I have found the solution to my problem.

To detect the location of the terrain with respect to the object I ws trying to place, I was using a raycast down from the origin of the object I was trying to place and setting the object’s position to the hitInfo’s ‘transform.position’ field. When I switched to using the hitInfo.point field, my object then aligned properly with whatever the slope of the terrain was at that point. Here is the code that I’m using that works properly:

if ((raycastHit = Physics.Raycast(instantiatedModelForPlacement.transform.position, Vector3.down, out hitInfo)))
        {
            instantiatedModelForPlacement.transform.position = new Vector3(instantiatedModelForPlacement.transform.position.x, 
                                                                           hitInfo.point.y + 
                                                                           (instantiatedModelForPlacement.collider.bounds.size.y / 2) + 0.00    1f, //the small offset here is to get out of the collision
                                                                           instantiatedModelForPlacement.transform.position.z);

            instantiatedModelForPlacement.transform.rotation = Quaternion.FromToRotation(instantiatedModelForPlacement.transform.up, hitInfo.normal) * instantiatedModelForPlacement.transform.rotation;
        }

Note the use of hitInfo.point.y to obtain the location of the terrain’s y coordinate. instantiatedModelForPlacement is the model that the player is holding in front of them trying to place on the ground. There is more to this script, but this bit is the relevant part to my initial question.

Hope this helps someone else some day.