- Home /
How do I generate this type of terrain randomly on runtime?
Hi there! does anyone know how I should go about creating similar terrain like in the first image and inverted so that the majority of the map stays flat except for the map edges (lead into ocean) and create rivers and lakes? Also how would I make it randomly generate per new game? I'm new to Unity so I'm not sure what to look up for specifics on this topic. Thank you for reading and hopefully enlighten me on this since it will greatly improve progress on my game.
Answer by fafase · May 18, 2014 at 07:42 AM
First it would be easier if you would use a square plane, sure it would add some triangles but it would not change the visual aspect since the edges are meant to be underwater.
But in order to find the edge vertices, a polygon is more complex. In a plane, you would have to create a method iterating through the mesh and finding the vertices with min x, min y, max x and max y. If a vertex contains one of those, he is an edge vertex.
void Start(){
Vector3[] edgeVertex = GetEdgeVertex();
// Run your method to shape the plane
// Discard action on the vertices containes in the list.
}
Vector3 []GetEdgeVertex()
{
List<Vector3>list = new List<Vector3>();
Mesh mesh = GetComponent<MeshFilter>().mesh;
foreach(Vector3 v in mesh.vertices){
// if the vertex is on the edge, add it to the list
if(v.x == minX||v.x == maxX||v.z==minY||v.z==maxZ)
list.Add(v);
}
return list.ToArray();
}
I am quite doing this by head so this may give you a lead but may not be fully working...
my goal is to have a couple layers visible before it goes into water that way you get depth but i will be sure to use this to go off of first thank you. id still like to know how to get that similar effect that is shown in the picture
What effect? If you want to have some distance from the edge just get the edge guys and compare the position of the vertex you are dealing with and if that distance is greater then apply a y value to the vertex. Then you get relief.
You would probably want to look into using heightmaps to control the topography of your terrain with a simple grayscale image.
Your answer
Follow this Question
Related Questions
How do i tell what gameobject im on 1 Answer
How to create “broken glass” animation? 0 Answers
Instantiated objects not appearing in scene or game view 2 Answers
How can I use feature recognition on terrain? 1 Answer
Terrain Destruction(crater) 0 Answers