Auto-moving objects to surface of another object

Is there a way create an editor script that will take all of the selected objects in a scene and transform them so that they are located at the surface of a terrain or a landscape model?

Sure. IINM, the script wiki includes some scripts that perform an operation on all currently selected transforms, so that should get you most of the way there. From there, you'll most likely want to raycast downwards from each object, and then move the object to or near the intersection point (or something to that effect - the details will depend on what behavior you want exactly).

Ok, so I came up with this code:


static function Normalize() {

for (var obj : GameObject in Selection.gameObjects)
    var hit : RaycastHit;
    if(Physics.Raycast(obj.transform.position, -Vector3.up, hit))
        var coll : Collider = obj.GetComponent(Collider);
        var bottom = coll.bounds.max.y
        obj.transform.position.y = obj.transform.position.y - hit.distance + bottom;


Except the minumum bounds is not resulting to what I expected.