Jump to content
  • entries
    743
  • comments
    1924
  • views
    583681

Random Caves

Sign in to follow this  
Aardvajk

1104 views

Quick Saturday morning update. Only have an hour on Saturday before the meet up with non-technical friends to set the world to rights.

Still very ugly, but I'm randomly generating cave structures now. I was going to use the perlin noise for this but didn't really work so I've just implemented a rather simple system based on a brute force flood-fill algorithm.

randomcave.png

Start with a finite 3D grid filled with ones. Set a variable called "current" to 2 then iterate over the grid N times. When you find a cell that is set to "current", check the cells above, below, right, left, in front and behind to see if they are a 1. If so, and if a random coin toss is heads, set that adjacent cell to "current" plus 1. Increment "current" and back to the main loop.

Then run over the grid and set any values that aren't 1 to 0. Then iterate the grid and for each cell, make the necessary faces to enclose it based on its neighbours for the graphics, and make a static physics body for the physics.

So you get a guaranteed interconnectedness in the cave structures and can encode the entire cave in an srand() value, so can then manually add specific features to it.

Not a lot else to say at the moment. I want to look into using some sloped cells as well as the square ones to round this off a little. Should be possible to do another run over the grid and look for specific patterns to replace a cube with a wedge in places maybe.

All good fun. Thanks for stopping by.

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 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!