Friday, April 6, 2012

Interesting Perlin noise caves

I'm not a big fan of using Perlin noise to generate random terrain - mostly because the results are uninteresting and you have so little control over it. However; I came up with a use for using Perlin noise to generate interesting caves that I haven't seen before.

Step 1: Generate a map of solid rock. Use Perlin noise (or whatever) to make it of varying density.
Step 2: Place points of interest in the rock.
Step 3: Use a pathfinding algorithm to connect those points using the rock density as movement cost.

This will create a a map that is guaranteed to connect all the interesting points and the paths between them will wind, curve, connect, and split trying to follow the path of least density between the points. By varying the size of the path finder or removing low-density tiles near the path, the caves can be made to look more interesting.

Here's an example that connects 9 points on a map that is 120 by 40 tiles.




And here is a view that shows the density of the rock, the lighter it is the more dense it is and the less likely a cave will go through it.




There you go, caves that twist and wind and widen and narrow from point A to point B.

5 comments:

  1. Nice use of perlin noise indeed!

    ReplyDelete
  2. I'm hoping you can help. I'm trying to remake C:SOTN multiplayer and I'm having a hard time with collision detection. The detection is fine but not the resolving. How do i know the difference of them hitting a wall, ceiling or floor. and my ramps are so hacked... I recently found something with will, no matter what, project them back out of the object but I know nothing about the conditions of that collision such as should I eliminate their Y velocity because they hit the floor or the X because they hit a wall. IDK. Anything would help.

    If your interested in my project feel free to ask. I'm writing it in Python and OpenGL.

    ReplyDelete
  3. Ah, yeah. I've used Perlin for writing shaders in maya, but seem to remember that the heightmaps I generated with them were somewhat lackluster. What the heck does Notch use for Minecraft heightmaps, I wonder. That's a pretty neat application of perlin, though.

    ReplyDelete
  4. I've been toying with different generation algorithms for outdoor levels in my roguelike and this is really clever. Thanks for writing this!

    ReplyDelete