- Home /
Terrain Generation Problem
Good afternoon people.
Im trying to generate Terrain maps from textures using code. After some reading ,some hair pulling and a bit of tinkering i managed to produce terrains i was happy with.
Then i put together a test WebPlayer to check that every thing was working ok and ran into a problem. Im not sure what the exact word for it is but its related to basemapDistance and i can only describe it as a texture error.
Time for some images
When in the WebPlayer mode the terrain loses its texture when the distance becomes greater than basemapDistance. This also happens in PCStandalone mode. In the editor (top image) it works fine though with the heights and textures all reducing there resolution as you move away.
I can only assume there is a difference in one or more default values of some objects or that the editor has been nice enough to fix something silly that i have missed and not bother telling me about it.
Relevant Code Chunk Debug.Log("-----Building Terrain Data-----"); processing_state++; if (gui_text) { gui_text.text=processing_text[processing_state]; yield WaitForSeconds(0);; } this.terrain_data = new TerrainData();
this.terrain_data.splatPrototypes = splats;
this.terrain_data.SetDetailResolution (1024,tile_size);
this.terrain_data.heightmapResolution = res;
this.terrain_data.alphamapResolution = res;
this.terrain_data.SetHeights(0,0,this.h_map);
this.terrain_data.SetAlphamaps(0,0,this.a_map);
this.terrain_data.size = new Vector3 (tile_size*res,max_height,tile_size*res);
this.terrain_data.RefreshPrototypes();
Debug.Log("-----Building Terrain-----"); processing_state++; if (gui_text) { gui_text.text=processing_text[processing_state]; yield WaitForSeconds(0);; } Terrain.CreateTerrainGameObject(this.terrain_data); Terrain.activeTerrain.treeDistance = 5000; Terrain.activeTerrain.treeBillboardDistance = 1000; Terrain.activeTerrain.treeCrossFadeLength = 20; Terrain.activeTerrain.treeMaximumFullLODCount = 0;
Terrain.activeTerrain.detailObjectDistance = 0;
Terrain.activeTerrain.detailObjectDensity = 0;
Terrain.activeTerrain.heightmapPixelError = 25;
Terrain.activeTerrain.heightmapMaximumLOD = 1;
Terrain.activeTerrain.basemapDistance = 450;
Terrain.activeTerrain.castShadows = false;
Terrain.activeTerrain.Flush();
Hope someone can point me in the right direction. Thanks in advance, Mike
Answer by MPink · Aug 10, 2011 at 04:27 PM
Solved It.
But if i run into another problem like this i fear i may end up bald.
The problem was that the textures i was using in my splatPrototypes had been loaded using Resources.Load("Grass (Hill)") And they had not had there Read/write Enabled checkbox checked (in advanced settings for the texture importer).
Im still confused as to how this has fixed things but it did.
I would have thought if it wasnt checked then Resources.Load should fail but as its something to do with reducing LOD i could just understand it only failing when i started playing with basemapDistance.
What i cant understand is why there is why the Editor and StandAlone players produce different results :?
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How to generate random terrain like platforms for a 2.5D game. 0 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Possible Infinite Terrain Plane? 3 Answers