Jump to content
  • Advertisement
Sign in to follow this  
3dmodelerguy

Unity Procedurally generate water around a procedurally generated map

This topic is 700 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I have been playing around with the idea of building a survival / crafting / rogue-like / etc top down 2D game in Unity3D and been building out very simple implementations of the core gameplay mechanics the past couple of weekends (character animation / movement / attacking, health / stamina system, inventory system, basic GUI for health / stamina / inventory, building / destroying structures, etc.). Now I am working on some basic procedural map generation. From what I have read, the easiest (maybe best for my needs) is to basically do multiple passes of using different noise generation to generate the different layers of my map. Currently I am doing one pass of simplex to generate the basic ground map (dirt / sand, grass, dark grass / swamp) and so far pretty happy with it:

 

w5pqeF1.png

 

The issue I am now facing is that I want to procedurally generated water surrounding this map to basically acts as a natural barrier to keep the user within this map (instead of just having a random point where the user can't move). Noise generation does not seem like it would work for this since I need it to only be around the map (and be pretty thin but still have some "natural" looking form instead of just being a straight line type thing) and noise generation is well, random.

 

What would I have to do to achieve something like this?

Share this post


Link to post
Share on other sites
Advertisement

The trick is combining the noise with a gradient emanating from the center of the map, so that it forms a sort of island.

 

I would basically combine the noise (if normalized from zero-one) with a gradient (also normalized) by adding 0.5 to the gradient and then the noise and then multiplying those two values together to get an 'on land' value that has a varied perimeter if you assign some threshold. The gradient could be something as simple as the inverted distance from the center of the map to the extent of either XY dimension, so that at the middle you have a full value of 1, and then by the time you reach the edge or near a corner you're at 0.

Share this post


Link to post
Share on other sites

Noise is a giant combinatorial playground.  Sadly I can't show any visual examples because my noise code is long lost to the ether, but I'd do something like this:

 

1.  Convert your coordinates to polar coordinates.

1.  Make a circular gradient function that takes your polar radius.

2.  Apply a step function at your desired radius to make an circular island instead of a fuzzy ball.

4.  Go back and apply noise to the radius of your gradient.  Now you have a weirdly shaped island.

 

Then you can just blend that with your existing map to get an island with biomes.  Your island mask is the control, so you don't need to futz around with normalization or multiplication.

 

Note that this will not play nice with height, or your coasts will be weirdly "cliffy".  If you want to add mountains and such with real height figures, you'll need something like what deftware suggested, or something more sophisticated.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!