- Home /

# How could you create a low poly land generator(with water)?

Ive been working on a game, Escape the Storm which i wont disclose at the moment but I have had a couple of problems like how i could generate a low poly land mass (Including water.) This has bugged me for about a month and i still cant find anything on this topic. I would appreciate any help from anyone in the community.

-Thanks

You can't find anything on on this topic? Did you search for procedural mesh generation, or mesh generation at all? Perlin noise? There are dozens of tutorials and sample scripts for this.

@Cherno I tried looking probably everywhere though i might have missed something, if you have any links that you may think will help deffinately send them, though i did look everywhere.

The Scripting API for Unity's Mesh class has an example for runtime mesh generation which will get you started. Functions for Perlin Noise are also included with Unity and should be in the User Manual or API.

**Answer** by Glurth
·
Apr 23, 2018 at 06:20 PM

-Start by generating a set of X random points on a 2d plane, in your map area. Add to this set of points, the corners of the map.

-Compute the (non-overlapping) triangles between all these points. (This is a tricky, but not-impossible algorithm. It can be slow, but if you don't need to generate the map during play-time, should be fine.) The (very inefficient) version I use works like this:

```
Generate a line segement from every point to every other point
Compare every line segment, against every other line segment:
if they intersect(excluding-endpoints), discard the longer line-segment.
This will yield a list of line segments that are the edges of triangles, but occasionally, depending on the order of processing, the edges of a polygon. So, one more pass is needed.
Compare the full list of lines against every line in the filtered list:
if the full-line line does not intersect ANY lines in the filtered list- add it to the result list.
```

-The results list will contain a line segment for every triangle edge.

-Converting this triangle-edge line-segment list into a list of triangles requires another algo:

```
Compare every line segment against every other line segment
if they share an endpoint,
note the endpoints that they DONT share
search all line-segements for one with BOTH of those unshared endpoints
if one is found, create a triangle using the one shared point, and the two points unshared endpoints
```

-Now that we have computed all our intersection tests on a 2d-plane, we can adjust the height of each vertex (I like using perlin noise for this). It is at this step you can account for water, if the vertex is below the "water level", set it to the water level.

-Now you have a set of triangles, and can easily generate a mesh. You may wish to consider making the "water level" triangles a seperate sub-mesh, so you can apply a different material to it in the MeshRenderer. Also keep in mind, you may need to create a new set of vertices for the mesh: each vertex has it's own normal(used for shading), so each triangle will probably want its OWN version of each vertex.

(e.g. Output Map note-This is a different run, with more points, that the algorithim pic above.)

@Glurth If you could give me a link or even better a tutorial on how i could do this as im not that good at Perlin noise and if i would be and if i would understand i wouldnt be here. If anyone else has anything that can help please write a comment

Perlin noise is just a smoothly-changing random number generator that takes two values (x,z coords) as parameters. First two google results for "perlin noise unity":
https://docs.unity3d.com/ScriptReference/Mathf.PerlinNoise.html

https://www.youtube.com/watch?v=bG0uEXV6aHQ (have not watched it myself)

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Object generator? 1 Answer

Terrain Triangle Generation 1 Answer

Starting a roguelike, maze generator problem. 1 Answer

c# generator problem with counter 0 Answers