Structures on a Procedural Landscape

I’m currently working through a course project for school and I’m trying to procedurally generate the ground terrain, which I have working. However, I’d like to establish walls around the ground that line up with the terrain to create an arena and have my structures that make up the map not get “eaten” by the terrain’s undulation on the z axis.

I think I can fix the structures by setting up a line trace from the “corners” of the structures and accept the longest trace and set the location equal to that on the z-axis. This would cause some overlap of the undulation, but would minimize it. However, I can’t seem to figure out how to setup the line trace properly.

The walls, I am unsure of the best method of setting them up, but I suppose I could just find the boundaries of the terrain and just create super big walls in static positions.

Best bet would probably be to create landmass brushes to flatten the landscape a bit and have an editor utility widget that moves a brush from a pool placed in some out of the way place, then scales the brush to roughly match the structure size.

Standard approach that has always worked is to use DTM in image format to override the zone.

in essence, read where the place is supposed to be (top right of source map), scan it’s area it’s supposed to cover for the mid point, override the whole area by taking that mid point height and adapting it by the extra DTM data for that zone.

If your data is correct, then the entry points are accessible because the mid point ensures that the area always scales up or down to grant a smooth(ish) path.

This approach will likely fail if you have extreme high/low in the sample area though. But generally speaking that’s a procedural mistake for most landscapes.

For grounding structures on uneven terrain, one line trace per corner works, but trace from above and use the lowest point as the base rather than the highest, so the footprint doesn’t float.

  1. For each corner (and the center), get the world location, add Z +5000 as Start and Z -5000 as End, and call Line Trace By Channel (Visibility or a custom Terrain channel; make sure the terrain mesh has collision, and for a Procedural Mesh Component enable Create Collision / Use Complex as Simple).
  2. Take Location.Z from each Hit. Use Min (or just keep a running float) to get the lowest hit, then set the structure’s Z to that value. Using the lowest point means nothing floats, and the extra part of the building simply sinks into the hill, which looks fine if you give the building a foundation skirt (a tall base mesh) that extends below.
  3. For the arena walls, use a Spline Component around the perimeter and a Spline Mesh per segment, tracing at each spline point the same way, so the walls follow the terrain. Or if the terrain is a heightmap, sample the height function directly instead of tracing.
  4. If you want the area flat, run the traces first, then flatten (or offset the vertices) inside the footprint to that Z before spawning the structure.

Ignore the structure itself in the trace via Actors to Ignore, or it will hit its own collision.