- Home /
Terrain Details below ground
Hello, I have a problem with my dynamically generated Terrain. I want to add details (grass) which I basically do this way:
DetailPrototype detailGrassProto = new DetailPrototype();
detailGrassProto.prototype = Resources.Load("prefabs/AlienGrass") as GameObject;
detailGrassProto.usePrototypeMesh = true;
detailGrassProto.renderMode = DetailRenderMode.Grass;
terrainPrototypes[0] = detailGrassProto;
terrainData.detailPrototypes = terrainPrototypes;
for (var y = 0; y < terrainData.detailHeight; y++) {
for (var x = 0; x < terrainData.detailWidth; x++) {
float height = terrainData.GetHeight(y, x);
if (height > terrainSize.y / 2) {
map[x, y] = 1;
} else {
map[x, y] = 0;
}
}
}
The problem is, the grass seems to be generated at the height of 0. So I always see only half of it through the terrain. Has anyone an idea how to solve this? Thanks!
Answer by Tobias Reich · Nov 17, 2013 at 08:06 PM
Ah, I found the solution. So for everyone who might have the same problem. The mistake is to think of the grass as an object that is placed there. So instantiating it like
detailGrassProto.prototype =
GameObject)Instantiate(Resources.Load("prefabs/AlienGrass"));
is wrong and leads to objects on your terrain. Instead you have to add a texture to the prototype like this:
detailGrassProto.prototypeTexture =
(Texture2D)Resources.Load(TEXTURE_GRASS, typeof(Texture2D));
Your answer
Follow this Question
Related Questions
Terrain Details Point Filtering? 0 Answers
Detail mesh pipeline 1 Answer
Grass texture transparancy Terrain not working 0 Answers
Terrain Detail Texture? 0 Answers
Should Heightmap Resolution be one greater than Detail Resolution? 1 Answer