nawerhub.blogg.se

Unity land generator algorithm
Unity land generator algorithm









  1. #Unity land generator algorithm full#
  2. #Unity land generator algorithm free#

I've created something similar to your first image in JavaScript. Also, it has a tendency to spawn continents too close together, resulting in something that looks more like a river than continents.ĭoes anyone happen to know a good algorithm for generating realistic continents on a grid-based map while keeping control over their number and relative sizes? The problem is that after placing the first few continents, it's possible to pick a starting location that's surrounded by other continents, and thus won't fit the new one.

unity land generator algorithm

This technique is part of the algorithm used in Civilization 4. While Perlin noise (or similar fractal-based techniques) is frequently used for terrain and is reasonably realistic, it doesn't offer much in the way of control over the number, size and position of the resulting continents, which I'd like to have from a gameplay perspective.Ī second option is to start with a randomly positioned one-tile seed (I'm working on a grid of tiles), determine the desired size for the continent and each turn add a tile that is horizontally or vertically adjacent to the existing continent until you've reached the desired size. One option is to generate a heightmap using Perlin noise and add water at a level so that about 30% of the world is land. I've experimented with a few alternatives, but haven't hit on a real winner yet. Output Map note-This is a different run, with more points, that the algorithim pic above.I'm working on a Civilization-like game and I'm looking for a good algorithm for generating Earth-like world maps. 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. 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. Now you have a set of triangles, and can easily generate a mesh. 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 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). If one is found, create a triangle using the one shared point, and the two points unshared endpoints Search all line-segements for one with BOTH of those unshared endpoints Converting this triangle-edge line-segment list into a list of triangles requires another algo: Compare every line segment against every other line segment The results list will contain a line segment for every triangle edge. If the full-line line does not intersect ANY lines in the filtered list- add it to the result list.

#Unity land generator algorithm full#

So, one more pass is needed.Ĭompare the full list of lines against every line in the filtered list: 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. If they intersect(excluding-endpoints), discard the longer line-segment. In computing, procedural generation is a method of creating data algorithmically as opposed to manually, typically through a combination of human-generated.

unity land generator 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Ĭompare every line segment, against every other line segment: (This is a tricky, but not-impossible algorithm.

unity land generator algorithm

Compute the (non-overlapping) triangles between all these points. Add to this set of points, the corners of the map.

unity land generator algorithm

However, if the player now go back to section B again, it should be generated with the same 100 random numbers as it was the first time in order for the section to look the same. The player proceeds to section C which is 100 yet different numbers and section B is destroyed.

#Unity land generator algorithm free#

Start by generating a set of X random points on a 2d plane, in your map area. The generated section A is destroyed at the same time to free up memory.











Unity land generator algorithm