Sign in to follow this  

Any suggestions for imroving my procedural road generation?

This topic is 416 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

The final goal is to create a road system similar to the one in Diablo2. A random enterance and exit are plotted on the map, then a winding path connects the two nodes. I have implemented a system that selects two random places on the edge of a map, then connects them. My issue is that the path is rather boring. Are there any good ways to improve the path my road takes? This is what I currently use to create the path:

        private List<Vector2> generatePath(Vector2 p1, Vector2 p2)
        {
            List<Vector2> nodes = new List<Vector2>();
            nodes.Add(p1);
            while (!p1.Equals(p2))
            {
                float xDiff = p2.X - p1.X;
                float yDiff = p2.Y - p1.Y;
                double atan = Math.Atan2(yDiff, xDiff);
                double quadrant = Math.Round(4 * atan / (2 * Math.PI) + 4) % 4;

                if (quadrant == 0) p1.X++;
                if (quadrant == 1) p1.Y++;
                if (quadrant == 2) p1.X--;
                if (quadrant == 3) p1.Y--;

                nodes.Add(p1);
            }

            nodes.Add(p2);

            return nodes;
        }

Share this post


Link to post
Share on other sites

I've done something like this once, but used A* with weights in map according to different terrain types/features (rocks, dense wood etc). This way the road follows nicely the landscape, walking around large rocks or lakes, for example. It's good to make rivers, also, just use the height of the terrain cell instead of the "difficulty" to pass.

 

Another way (but never implemented) could be using waypoints. Put some random points between the start and the end and force the road to pass through them. You could add later features on these points, like inns, fountains, towns, or something else to justify a nearby road.

Edited by arka80

Share this post


Link to post
Share on other sites

I've been avoiding a* since I'm not really sure how to implement it. I planning on generating the road first and then the landscape around it, does it really matter what order I do this in?

 

I like the idea of using waypoints, I may attempt something like that. I was looking in to midpoint displacement algorithms which would make the road look more natural, the issue is that it still takes the shortest path.

Share this post


Link to post
Share on other sites

This topic is 416 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.

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

Sign in to follow this