I have the code for a basic grid in Unity that generates a set of vertices. That much of this works, however I’d like to also create dips and hills in the surface. I’ve tried altering the y property, however that’s causing things to go rather weird. This is the code I have so far.
void Start () {
vertices = new Vector3[(xSize + 1) * (ySize + 1)];
for (int i = 0, y = 0; y <= ySize; y++, i++)
{
for (int x = 0; x <= xSize; x++)
{
vertices *= new Vector3(x, i + y, y);*
}
}
}
When I alter the Y, it causes everything to go… screwy. Sometimes all vertices to the left, others all to the right. How can I correct the math to generate smooth random hills? (Ignoring the i/y, which is just testing to try to get the generation working, however where I thought the code for the displacement would go).