Question is to big to explain in the description...Sorry for the obese post haha

So I have an Editor script that allows you to put an object directly on top of the one below it. This is useful if you don’t want to go in and rotate around your object to make sure its sitting on a surface at the correct angle. What the script does is very simple. It raycasts down and if the raycast hits something, the object will be placed on the point where the raycast hits (hit.point) then it rotates the object so that it is flat on the hits normal. This works perfectly if you are moving an object with no volume…but obviously that’s not what I want. For example, with my current script, if I have a cube above a sphere and to the left a bit; with the cube selected, if I activate the button that performs the script, the cubes position will be perfectly on the hit.point and it will be rotated correctly. That’s not good enough though, because the cubes position is in the middle of the cubes mesh, so the cube is halfway inside of the sphere. So in conclusion, what can I do to find the distance I need to move the mesh so that it isn’t completely intersecting the mesh below. Also I guess I need to find the direction to offset. So distance and direction of offset, how do i calculate it? My current code is pretty simple…more simple that my explanation of the problem!

public class PlaceSelectedOnSurface extends ScriptableObject
{
    @MenuItem ("Keenan's Cool Tools /Transform /Place Selected On Surface ")
    static function CreateWizard ()
    {
        var transforms : Transform[] = Selection.GetTransforms(SelectionMode.Deep | SelectionMode.ExcludePrefab | SelectionMode.OnlyUserModifiable);
       
        if (transforms.Length > 0 && EditorUtility.DisplayDialog("Move Selected Objects to The Surface Below?", "Are you sure, you are moving " + transforms.Length + " objects", "Yes", "No"))
        {
            var transform : Transform;
            for (trans in transforms)
            {
                var hit : RaycastHit;
                if (Physics.Raycast(trans.position, Vector3.down, hit))
                {
                    var scale : Vector3 = trans.localScale;
                    trans.position = Vector3 (hit.point.x, hit.point.y, hit.point.z);
                    trans.rotation = Quaternion.LookRotation (trans.rotation.eulerAngles, hit.normal);
                }
            }
        }
    }
}

I am no expert, but isn’t there a way to get the individual vertices? if you are dealing with cubes, and other basic geometric shapes (i.e. no unique abstract meshes) you could simply find the distance form a point above you, to the one opposite of it, then divide the distance in half.

hmm, yeah maybe somehow I could find any vertices on the object thats being moved and get its distance from the actual objects position that its a vertice on… Then move the object away from the hit pint by that amount. If the object being moved was a sphere it would work perfectly I think. It would be way easier to just run physics in the editor and stop the object when its where you want it. Is that possible, running physics in the editor?