# Low-polygon rock generation [Maybe Random Vertex Displacement?]

So I’m trying to create a procedurally generated asteroid field for my game, but first I want to develop a means to generate the asteroids themselves.

The game is low-poly and I heard that I could just use random vertex displacement, but how do I do that exactly?

Apologies, I’m very new to Unity, but it’s just a matter of me being unfamiliar to the language of C#.

Edit - I have figured out my method so you don’t need to answer thanks.

Try adding/subtracting a vector along the vertex normal like this…

(pseudo code)

float diameter = (mesh.bounds.max - mesh.bounds.min).magnitude;
float maxDisplacementPercent = 0.2f;
float maxDistance = (diameter * maxDisplacementPercent);

// Very important to get/set the whole arrays at once and never use mesh.ARRAY_NAME[iv] directly.

Vector3[ ] vertices = mesh.vertices;
Vector3[ ] normals= mesh.normals;

for (int iv=0, nv = vertices.Length; iv < nv; iv++)
{
float randomAmount = (2.0f * random_number_between_0_1) - 1.0f; // random number between -1…1
randomAmount *= maxDistance;

vertices[iv] = vertices[iv] + (randomAmount * normals[iv]);

}

mesh.vertices = vertices;
mesh.RecalculateNormals();

Hope this helps

You’re welcome to take a look around my MakeGeo project. It can make a bunch of 3D primitives, one of them being a sphere. If you added random offsets to the vertices before using them, it would make for lumpy chunky rocks.

Or you can make an icosphere in Blender3D, import it and then moosh its vertices around procedurally and write them back to the mesh.

MakeGeo is presently hosted at these locations:

https://bitbucket.org/kurtdekker/makegeo