Trying to snap to ground and have ground snap back to object

When I am placing an object is there a script that will have the object not only snap to the ground, but the ground will also snap to the object so I don’t have a gap? I guess some sort of script that terraforms the ground.

If I go to a mountain and nothing is flat and I want to place a building, it isn’t going to snap correctly and also half of the base will go into the ground. If the ground itself was changed so the building was placed correctly, could this be done?

I’ve attached the script for snapping to the ground, however it snaps too much into the ground. Would it be possible to alter the script and add the above as well?

Script location: Using Unity Editor Extensions to Snap To Ground when placing gameobjects - Unity3D.College

Thanks

8152436–1059146–SnapToGround.cs (578 Bytes)

You can hack up code to do this or you can remake the prefab so that its pivot point is higher, such that when placed, more of the object is underground.

This either means different depth-set prefabs for sloped vs flat ground, or you could also tilt stuff to try and conform to the ground. Either way, the solution is going to be completely dependent on just how uneven you’re trying to contour to.

Another approach is to always have an extra flange below objects, eg, continue them far into the ground, letting them be placed and not have daylight visible below them.

1 Like