Random Terrain Generation

I’ve made a simple randomized terrain generation using simple (1 by 1) cubes. However, right now I have a problem where cubes are floating in the air. How could I make it so that cubes that are not directly touching other cubes(by the faces of the cubes) will drop down till they are touching another cube (On the face of the cube). Please answer in C# (if you provide code). Thank you.

As kryptos said, you should use physics. Just add a rigidbody to every mesh and pregenerate (without code, I mean) a big surface with a rigidbody attached to it and check all the constrains (if you don’t check the constrains, the floor will fall itself… which is not likely to happen this soon in the morning).

Adding a rigidbody will assure you that cubes don’t overlap and also that they have a pretty much “normal physcis” appearance. Don’t forget to adjust gravity if you need to in “project settings” → “Physics”.

Add a rigidbody to the cubes then round off their position.