0 votes

Hello,

I've followed a guide on how to make procedurally generated worlds from Codat in youtube, from there I started trying things like spawning objects around the world such as trees and some kind of houses.

I've done that by iterating over each vertex of a chunk with a probability of spawning an object above said vertex.
This works fine for trees, however, I haven't found a way to make procedurally generated roads above the terrain.

I'm trying to learn how to make worlds with villages and dungeons and roads such as those in Cube World, however, the biggest difference I see is that Cube World uses voxel terrain and I don't. How would one go about making something like that? I suppose for a village one could just design an area and spawn houses iterating through each vertex, but I'm kind of lost about the roads.

in Engine by (12 points)

I don't know much about proc gen, but here's my quick and dirty solution: keep the same approach as for trees and houses, and add "road markers" or some type of invisible "road" object. Once generation is done, iterate over those road markers and try and link them based on proximity and sightlines.

something like:

# before that, collect all of the markers into the road_markers array
var road_graph = [] # list of edges
var start = road_markers[0].pos
var end = road_markers[1].pos
road_graph.append([start, end])
for marker in road_markers.slice(2, road_markers.size()):
    if marker.pos.distance_to(start) < marker.pos.distance_to(end):
        road_graph.append([start, marker.pos])
        start = marker.pos
    else
        road_graph.append([end, marker.pos])
        end = marker.pos

then iterate through the list of edges and build your road from there:

for road_segment in road_graph:
   create_road(road_segment[0], road_segment[1]) # takes a start and end position

You'll need to decide what to do with objects intersecting with the road, whether one takes prevalence over the other (or just decide randomly).

The resulting road network could look quite wonky though. My approach to building the graph is pretty stupid, but it's a start.

For the create_road method, I'd try and simply stretch a simple cube from the start to the end, just to see how the roads look. You'll need to either divide the road into smaller segments that more closely fit the terrain, or raise/lower the terrain to accommodate the road.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.