- Home /
Tree position on random Terrain (y axis)
So - I have random generated terrain - here's fragment of my script:
public void GenerateHeights(Terrain terrain, float tileSize)
{
float[,] heights = new float[terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight];
for (int i = 0; i < terrain.terrainData.heightmapWidth; i++)
{
for (int k = 0; k < terrain.terrainData.heightmapHeight; k++)
{
float MapFix = terrain.terrainData.size.x/terrain.terrainData.heightmapWidth;
float MapFix2 = terrain.terrainData.size.z/terrain.terrainData.heightmapHeight;
heights[i, k] = Mathf.PerlinNoise(((float)i / (float)terrain.terrainData.heightmapWidth) * tileSize, ((float)k / (float)terrain.terrainData.heightmapHeight) * tileSize)/randomNumber;
if(Random.Range(0, 1000)==1){
Instantiate(tree, new Vector3 (k*MapFix,heights[i, k],i*MapFix2), Quaternion.identity);
}
}
}
terrain.terrainData.SetHeights(0, 0, heights);
}
And - X and Z is ok, but Y is 0. How to fix this?
Comment
Your answer
Follow this Question
Related Questions
How to generate random terrain for a platformer 0 Answers
Generate an object in random positions ? 1 Answer
Unity Voxel Terrain and structures 0 Answers
Yield after spawning object 1 Answer
Random object placement. 1 Answer