Creating flat spots for structures in infinite procedural terrain

I’m generating an infinite map(thanks to @5uphi and his plugin Terrain presets), and I want structures to be placed, but I have an issue where if I just place it at a certain position, even if it’s at the top of the terrain, quite often it’s clipping into the terrain and/or floating.

I’ve done a thing where when the structure generates it alters the terrain around it to be the correct level, but this creates harsh corners, and often will punch holes through the terrain since it’s optimized terrain(meaning it’s not a brick of terrain, it’s just surface terrain)

I also tried adding in a restriction to where it can place them based off the size of the structure, and while this works if I do the same thing I tried first, it still has the problem of harsh corners, unless I crank the difference allowed between the corner heights down, which gives me the problem of it barely generating them, if at all.

So is there a way to tweak the noise to generate flat sections? it doesn’t have to be a specific size, it preferably would be rather quick, also preferably works in parallel Lua

I didn’t post the code due to the sheer amount, but the link I sent has the source code available, and I’ve not edited it in extreme enough places for it to not work if it works with the original SC, if you want my code, let me know, and I’ll send it for you :smiley:

You can try and blend the terrain with a flat area to make space for the building, that would at least be smoother. Choose a height, such as the average height in an area, and force all points inside that area to be that height, with the manual height gradually fading away with some distance. I do this trick to make the spawn area predictable in my own terrain gen.

1 Like

I’ve done it here so that the outer part of the map uses a random seed, but a small center area (spawn) uses a fixed seed. It’s hard to see because I’ve also used a funky octagon-like shape for the blending function.


I will attempt to implement this, although I probably won’t finish implementing it until tomorrow(or if I do tonight I probably won’t respond till tomorrow), I did try something similar to this, although for some reason I made it so it was basically generating the terrain twice, but visualizing only the second time(since I needed the heights), and this slowed it down so each 64x64 stud area took ~20 seconds to load, which before hand it was taking ~5, but yeah I’ll try my best and hopefully it’ll work out better this second time

ok so I’ve reached a slight issue, yes it will go to a good level, but again it’s creating very harsh edges, I would go through and smooth it out, but I’d rather not have to try and effect other chunks, especially when quite often the other chunks have been generated already.

I’m thinking maybe going with a method that checks if the adjacent chunks are going to try and generate a structure, and if so, it fetches the planned height(which would be randomly based off the terrain normally), and then lerps between it’s originally planned height, and the structure’s planned height, I’m worried it might cause some lag, but I’ll burn that bridge later.

for now, it’s time for sleep since it’s 10:23 pm, good night

I implemented the whole

but that has the same issue with the rough edges

no matter what I did, I couldn’t get it to smooth itself

local Magi = math.floor(Magni((FX + X) * Size, (FZ + Z) * Size)) / Size

result = Lerp(result, Avg, Magi)

(result is the noise generated height, Avg is the average height from the adjacent chunk[FX + X, FZ + Z])

but yeah, I’ve literally spent ages tweaking seeing if it was maybe just the math that was off, but it appears to actually be the logic

@azqjanna if you could kindly give me a code example of what you did to accomplish this, I’d appreciate it, since I’ve spent long enough on this to almost have built the entire map manually lol

Edit : I literally just thought of an issue, its that they can generate next to one another, but doesn’t account for my alterations when getting the average height

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.