- Home /
For loop not starting from zero
I am trying to implement a biomes system into a procedural terrain generation system from Sebastian Lague. I made it so that the height multiplier of each terrain chunk changes based on which biome it is, but that results in the player being able to go under the map where two biomes meet. I am trying to make the edges of each chunk have a height of 0, so that they will connect properly. The issue is, the for loops don't seem to be starting at 0. I used to have the if statement that contains x <= 8 to be x == 0, but then nothing with the mesh would change.
for (int y = 0; y < borderedSize; y += meshSimplificationIncrement)
{
for (int x = 0; x < borderedSize; x += meshSimplificationIncrement)
{
float height;
if (x <= 8 || x >= 233)
{
height = 5.0f;
//Debug.Log(height);
//Debug.Log("x" + x);
}
else if (y <= 8 || y >= 233)
{
height = 5.0f;
//Debug.Log(height);
//Debug.Log("y" + y);
}
else if (y <= 32 || y >= 225)
{
height = heightCurve.Evaluate(heightMap[x, y]) * heightMultiplier;
height = height / 1.5f;
}
else if (x <= 32 || x >= 225)
{
height = heightCurve.Evaluate(heightMap[x, y]) * heightMultiplier;
height = height / 1.5f;
}
else
{
height = heightCurve.Evaluate(heightMap[x, y]) * heightMultiplier;
}
int vertexIndex = vertexIndicesMap[x, y];
Vector2 percent = new Vector2((x - meshSimplificationIncrement) / (float)meshSize, (y - meshSimplificationIncrement) / (float)meshSize);
Vector3 vertexPosition = new Vector3(topLeftX + percent.x * meshSizeUnsimplified, height, topLeftZ - percent.y * meshSizeUnsimplified);
meshData.AddVertex(vertexPosition, percent, vertexIndex);
if (x < borderedSize - 1 && y < borderedSize - 1)
{
int a = vertexIndicesMap[x, y];
int b = vertexIndicesMap[x + meshSimplificationIncrement, y];
int c = vertexIndicesMap[x, y + meshSimplificationIncrement];
int d = vertexIndicesMap[x + meshSimplificationIncrement, y + meshSimplificationIncrement];
meshData.AddTriangle(a, d, c);
meshData.AddTriangle(d, a, b);
}
vertexIndex++;
}
}
put a Debug.Log in the beginning of each loop and check, there doesn't seem to be an issue with the loops here
if it is 0 you are setting it to 5, I think is the issue.
if x
height = 5.0f;
if y
height = 5.0f;
Your answer
Follow this Question
Related Questions
How can I generate procedural 3D geometry faster? 2 Answers
Procedural Terrain Merge 1 Answer
Procedural Mesh From Random List Of Veritces 2 Answers
How to create voxel-based procedural terrain 1 Answer
How do i Offset a Shader Graph material? 0 Answers